我有一个工作@ManagedBean,我想用@Named + @RequestScoped豆替代.
// Before
@ManagedBean
public class Login {
...
}
// After
import javax.enterprise.context.RequestScoped;
@Named
@RequestScoped
public class Login {
...
}
Run Code Online (Sandbox Code Playgroud)
只要我使用,一切都很好@ManagedBean.@Named没有@RequestScoped工作,但为每个EL表达式创建一个新实例.@Named + @RequestScoped但是会产生异常:当请求缓存不活动时,无法添加请求范围的缓存项
java.lang.IllegalStateException: Unable to add request scoped cache item when request cache is not active
at org.jboss.weld.context.cache.RequestScopedBeanCache.addItem(RequestScopedBeanCache.java:51)
at de.prosis.dafe.presentation.Login$Proxy$_$$_WeldClientProxy.getUsername(Login$Proxy$_$$_WeldClientProxy.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
...
Run Code Online (Sandbox Code Playgroud)
空beans.xml确实存在.是否有任何我不知道的陷阱或错误?我打赌我错过了一些东西,但它确实看起来像一个bug.我搜索了异常消息,但除了引发它的类的源代码之外没有找到任何东西.提前致谢!
更新: 它与我省略的代码有关.登录bean尝试在其构造函数中使会话无效,如果它是一个命名bean(不总是,如果我垃圾邮件F5,它似乎在几次后工作)就会失败并且作为托管bean工作.有人可以解释一下这种行为吗?
public Login() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
if (session != null) {
session.invalidate();
}
}
Run Code Online (Sandbox Code Playgroud)
代码来自该教程:http: //www.greenkode.com/2011/09/user-authentication-and-authorization-using-jaas-and-servlet-3-0-login/
| 归档时间: |
|
| 查看次数: |
3859 次 |
| 最近记录: |