请问关于OpenSessionInView的不起作用的问题!谢谢!

luoxiang2000 2008-02-27 03:10:13
在网上查了资料,有两种方式实现,可是我配置两种方式都有问题(我的是jsf + spring + hibernate):
1、
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate.support.OpenSessionInViewFilter
</filter-class>
</filter>

<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
这种配置了以后,运行出现java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?异常。

2、我不知道mappings里面的配置规则是什么?
<bean id="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors" ref="openSessionInViewInterceptor"/>
<property name="mappings">
<props>
<prop key="?????">这里怎么填写?</prop>
</props>
</property>
</bean>

附加我的web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>UserInterfaceDemo</display-name>

<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>

<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>

<filter>
<filter-name>HibernateOpenSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HibernateOpenSessionInView</filter-name>
<url-pattern>*.faces</url-pattern>
</filter-mapping>

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<welcome-file-list>
<welcome-file>route.jsp</welcome-file>
</welcome-file-list>
</web-app>
...全文
644 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
elesen 2008-03-19
  • 打赏
  • 举报
回复
麻烦贴一下吧。。。谢谢!
睿音 2008-02-28
  • 打赏
  • 举报
回复
[售后服务]
to luoxiang2000:刚想贴Interceptor的方法,结果。。。结贴了~~~~~
luoxiang2000 2008-02-28
  • 打赏
  • 举报
回复
还有我觉得用Interceptor的方法要好一些,这样就不用到web.xml文件中配置,如果两层是不同的小组写的话。
所以我最想用第二种方式解决这个问题。多谢。
睿音 2008-02-28
  • 打赏
  • 举报
回复
然后对filter最好这样配置,这个是我记下来的别人配置的一个配置方法。

<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
<!-- singleSession默认为true,若设为false则等于没用OpenSessionInView -->
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
睿音 2008-02-28
  • 打赏
  • 举报
回复
晕,纠正下。你配置了。
代码挨在一起没看到。你配的是*.faces 。所以lazyload的仅是.faces的请求。确定下现在你load时的请求是否是这个。
睿音 2008-02-28
  • 打赏
  • 举报
回复
你没有配这个:

<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>

你去
http://topic.csdn.net/u/20080228/09/7ee41ece-e9b1-45a2-8131-bef7452732bc.html
这个帖子看下。我贴的一个我的web.xml配置。
luoxiang2000 2008-02-28
  • 打赏
  • 举报
回复
谢谢,我改了,确实不饱错了。可是却不起作用??还是会报could not initialize proxy - no Session
是不是跟我的hibernate调用方法有关:
List reList = (List)this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
…………
}
}

改用this.getHibernateTemplate().find("From UserBean");也不行啊!!!!!
睿音 2008-02-28
  • 打赏
  • 举报
回复
我常用Filter的方法,所以对于你Interceptor的方法,我没有看。

对于你的Filter方法的错误。
首先提示的No WebApplicationContext found就是指web.xml中的这个配置是不存在的。

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

除此之外,你还需要加载应用程序上下文

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/applicationContext.xml</param-value>
</context-param>

这样你的spring才能跑起来。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧