jsf+spring+hibernate整合,于struts+spring+hibernate整合的过程非常相似(就不截图了,可以参考第一篇文章),但是前者相对于后者稍微麻烦一些。
第一步:初步整合,其过程以及基本配置,于struts+spring+hibernate整合的过程完全一样。
第二步:要加入jsf-spring.jar(可以到SourceForge上面去下)
第三步:在web.xml中加入如下listener
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
de.mindmatters.faces.spring.context.ContextLoaderListener
</listener-class>
</listener>
二者都要加,而且顺序不能变。
最好在加入下面的listener顺序没影响
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
否则会遇到下面的错误
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: /admin/login.jsp(16,4) '#{PersonBean.loginName}' de.mindmatters.faces.spring.factory.BeansEvaluationException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PersonBean': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.jsha.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:57)
root cause
javax.servlet.ServletException: /admin/login.jsp(16,4) '#{PersonBean.loginName}' de.mindmatters.faces.spring.factory.BeansEvaluationException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PersonBean': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:694)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:665)
org.apache.jsp.index_jsp._jspService(index_jsp.java:56)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.jsha.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:57)
控制台上的错误不太一样
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:102)
at org.springframework.web.context.request.SessionScope.get(SessionScope.java:88)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:283)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at de.mindmatters.faces.spring.factory.DelegatingVariableResolver.resolveVariable(DelegatingVariableResolver.java:101)
本文介绍JSF+Spring+Hibernate的技术整合过程,重点在于如何解决特定的配置问题,如引入必要的jar文件及在web.xml中配置监听器等。
285

被折叠的 条评论
为什么被折叠?



