这是在WAS8.0上运行的JSF 2应用程序.这是一个页面的"支持"bean的代码.
@Named("mySessionBean")
@SessionScoped
@Stateful
@LocalBean
@StatefulTimeout(unit = TimeUnit.MINUTES, value = 10)
public class MySessionBean implements Serializable {
@PostConstruct
public void init()
{
System.out.println("start MySessionBean: " + this.hashCode());
}
@PreDestroy
public void cleanup()
{
System.out.println("destroy MySessionBean: " + this.hashCode());
}
....
}
Run Code Online (Sandbox Code Playgroud)
web.xml中设置的会话超时值小于bean的超时.当我运行应用程序时,我看到来自@PostConstruct的打印输出,但从未看到来自@PreDestroy的打印输出.我尝试了以下两种方案:1.logout - invalidateSession; 2.只需等到会话到期.
我不是应用程序的设计者.设计者坚持将所有支持bean作为有状态会话bean.我认为更主流的方法就是让它们成为CDI bean.但无论如何,当我确实将注释更改为CDI时,我也开始从@PreDestroy获取打印输出
@Named("mySessionBean")
@SessionScoped
public class MySessionBean implements Serializable {
.....
Run Code Online (Sandbox Code Playgroud)
我的问题是,在第一种情况下我没有得到@PreDestroy方法调用的原因是什么?如果我不能看到@PreDestroy被调用,在那里我可以跟踪"后盾" bean的生命周期(在这种情况下,有状态会话Bean)的任何其他方式.谢谢!
我正在开发一个JSF 2项目.我已将login.xhtml页面定义为web.xml中的入口页面
<welcome-file-list>
<welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)
我还有一个过滤器来检查用户是否已登录
@WebFilter(filterName = "loginCheckFilter", urlPatterns={"/*"})
public class LoginCheckFilter implements Filter
{
@Inject
private LoginStatus loginStatus;
public void do Filter(...)
{
try{
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
String path = req.getRequestURI();
if(StringUtils.isNotBlank(path)
&& StringUtils.contains(path, ".xhtml")
&& !StringUtils.endsWith(path, "login.xhtml"))
{
if(loginStatus == null
|| !loginStatus.isLoggedIn())
{
res.sendRedirect(req.getContextPath() + "/login.xhtml");
}
else
{
chain.doFilter(request, response);
}
}
else
{
chain.doFilter(request, response);
}
}catch (Exception ex)
{
log.error(ex);
}
}
.... ....
}
Run Code Online (Sandbox Code Playgroud)
我的css文件以下列风格引用: …