解决问题(七)——jsf+spring+hibernate整合(一)

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)
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码匠君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值