想用hibernate的lazy方式,在网上看到这样可能会由于session关闭导致lazy不进来,于是想配置一下OpenSessionInViewFilter,在web.xml中配置如下 <filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
这样配置之后只要调用到action,就会报出下面错误:
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:70)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:241)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:227)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:171)我使用的版本分别是Struts1.3,Hibernate3.2,Spring2.5,tomcat6.0.20
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
这样配置之后只要调用到action,就会报出下面错误:
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:70)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:241)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:227)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:171)我使用的版本分别是Struts1.3,Hibernate3.2,Spring2.5,tomcat6.0.20
解决方案 »
- servlet的doget()方法为空,为什么返回空页面???
- java中oracle数据Date显示问题!!经验老到者来!!
- java中如何判断字符串数组中是否有某个字符串?(没分了,有人会帮我吗?)
- 为什么我添加的中文 调用以后显示的是问号 用了论坛的方法还是不能解决
- 求JSP实现图片水印效果代码~~
- 如何将客户端access库里的数据通过jsp提交到服务器端oracle数据库中,(两个星期了还没办法解决,上来求救>>>>!!
- 数据库连接池
- 在1.jsp中有一个表单和2个按钮b2,b3.怎样实现在按b2时把表单数据传到2.jsp.按b3时把表单数据传到3.jsp?
- 好着急呀,急求一个简单的jsp/servlet/java bean的例子
- 困惑???
- web打印 横向打印
- JavaScript要学哪些东西?
换成
<url-pattern>/*</url-pattern>
试试~
看看~应该跟你情况差不多,少了配置。
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>和<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>然后把struts-config.xml里面的<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/action-beans.xml" /> </plug-in>红色部分原来是把所有的spring配置文件都加在这里,现在只加了和action有关的xml,剩下的spring配置文件都放在web.xml里面上面蓝色字部分。我现在不清楚这样做之后是不是就在web级和struts两个地方都加载了spring的beans?这样做是不是有问题?
这里这样只加载了applicationContext.xml
如果applicationContext.xml里面没加载别的文件,那不会被加载
所以你这两个地方没冲突
最好加个<load-on-startup>0</load-on-startup>
值越大,优先级别越低