使用openSessionInViewFilter出现could not initialize proxy - no Session异常

KG071 2011-05-05 10:36:35
web.xml中的一个片段

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


配置了这个为何还是会有lazy方面的异常?
...全文
157 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
KG071 2011-05-06
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 yingzhuo2011 的回复:]

applicationContext-*.xml 之间有没有谁import谁这种关系啊。
[/Quote]

没有
yingzhuo2011 2011-05-06
  • 打赏
  • 举报
回复
applicationContext-*.xml 之间有没有谁import谁这种关系啊。
KG071 2011-05-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 yingzhuo2011 的回复:]

web.xml
Java code

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

<context-param>
<param-name>contextConfigLocation</pa……
[/Quote]



这是全部的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>GraduationDesign</display-name>

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

<!-- ******** filter ******** -->
<filter>
<filter-name>Spring character encoding filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring character encoding filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


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


<!-- ******** servlet ******** -->
<servlet>
<servlet-name>authimg</servlet-name>
<servlet-class>com.briup.run.web.servlet.AuthImg</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>authimg</servlet-name>
<url-pattern>/authimg</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>ValidateNameServlet</servlet-name>
<servlet-class>com.briup.run.web.servlet.ValidateNameServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ValidateNameServlet</servlet-name>
<url-pattern>/ValidateName</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>


<!-- ******** welcome file ********-->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
KG071 2011-05-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 yingzhuo2011 的回复:]

web.xml
Java code

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

<context-param>
<param-name>contextConfigLocation</pa……
[/Quote]

加了 我把整个web.xml传上来吧
yingzhuo2011 2011-05-06
  • 打赏
  • 举报
回复
web.xml

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

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext1.xml
/WEB-INF/applicationContext2.xml
</param-value>
</context-param>


这个没加吗?
cheneyfeng3 2011-05-06
  • 打赏
  • 举报
回复
openSessionInView 这个是有生命周期的。是再一次请求中有效的。如果的不是在一次请求中调用的。
yingzhuo2011 2011-05-06
  • 打赏
  • 举报
回复
爱莫能助了。 阿弥陀佛。
yingzhuo2011 2011-05-05
  • 打赏
  • 举报
回复
你没有配置事务!!!
KG071 2011-05-05
  • 打赏
  • 举报
回复
<ref local="sessionFactory"/>和<ref="sessionFactory"/>有区别吗?
KG071 2011-05-05
  • 打赏
  • 举报
回复

<filter>
<filter-name>Spring character encoding filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring character encoding filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


filter顺序应该也没错
KG071 2011-05-05
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 kevinpai2011 的回复:]

应该是2个session已经不是同一个对象了!
[/Quote]

用了OpenSessionInViewFilter,还会有2个不同的session?
kevinPai2011 2011-05-05
  • 打赏
  • 举报
回复
应该是2个session已经不是同一个对象了!
yingzhuo2011 2011-05-05
  • 打赏
  • 举报
回复
今天上午回复你的帖子有点草率,先跟你说声对不起啦。

“could not initialize proxy” 如果抛出这样的异常的话, 还是说明你声明了事务的。

我现在也一下子也吃不准你这个到底什么原因了。建议你测试一下,看看你持久层拿到session 和 OpenSessionInView的过滤器的新建的session到底是不是同一个对象。

我冷静地想一想症结或许在这里,大概是哪里配置错了,造成Spring的IoC容器启动了两个。

67,516

社区成员

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

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