HTTP Status 500 - Could not write content: could not initialize proxy - no Session
分析出现no Session错误的原因以及给出解决方案:
使用SpringMVC + JSON数据返回时,经常会出现no Session的错误:
报错原因:因为懒加载在提取关联对象的属性值的时候发现EntityManager已经被关闭,就报no session错误。

控制器类中的方法上添加了@ResporseBody注解,将方法的返回值利用jackson包自动转化为JSON字符串,然后放入响应消息体中,最后发送到浏览器;
然而jackson包都会自动调用对象的属性的get方法来获取属性的值拼接成JSON字符串,而调用get方法就需要自动发送SQL语句去查询关联对象的数据,结果发现EntityManager对象已经关闭了,已经无法在通过EntityManager对象去查询关联对象的get方法,所以就会报 no session异常。
解决办法:让关闭EntityManager对象的动作延后到提取懒加载对象的数据之后再关闭。
具体做法:在web.xml中添加一个过滤器OpenEntityManagerInViewFilter,使EntityManager对象的开启和关闭在视图层发生。
<!-- 解决no session问题 -->
<filter>
<filter-name>noSessionFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>noSessionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
HTTP Status 500 - Could not write content: could not initialize proxy - no Session的更多相关文章
- 【FAQ】【JSP】HTTP Status 500 - Summary(问题排查时候应该仔细分析所有的错误打印说明)
Question 1.HTTP Status 500 - Unable to compile class for JSP:'***' cannot be resolved to a type 原因分析 ...
- HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError: junit/framework/Test解决方法
java代码 package webViewer; import java.io.*; import junit.framework.Test; import com.aspose.words.*; ...
- Tomcat连HBase报错: HTTP Status 500 - java.lang.AbstractMethodError: javax.servlet.jsp.JspFactory.getJspApplicationContext
Tomcat中连接HBase数据库,启动的时候报错: HTTP Status 500 - java.lang.AbstractMethodError: javax.servlet.jsp.JspFac ...
- HTTP Status 500 ? Internal Server Error
getWriter()和getOutputStream()不能同时调用 HTTP Status 500 ? Internal Server Error Type Exception Report Me ...
- Exception:HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
主要错误信息如下: HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...
- HTTP Status 500 - org.apache.jasper.JasperException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException
HTTP Status 500 - org.apache.jasper.JasperException: com.sun.org.apache.xerces.internal.impl.io.Malf ...
- web项目引用Java项目,连接报错error HTTP Status 500 - Servlet execution threw an exception
错误信息 项目背景: 一个web项目引用一个java Project,项目中添加了引用,但是打开页面访问,总报500错误.提示:servlet初始化错误. 环境:Eclipse luna JDK: 1 ...
- 【ERROR】使用jquery的ajax出现error:readyState=4,status=500
使用jquery的ajax出现error:readyState=4,status=500,ajax代码如下: $.ajax({ url : "../toBeFinMisManage/show ...
- HTTP Status 500 - An exception occurred processing at line 35
HTTP Status 500 - An exception occurred processing JSP page /manage/addCategory.jsp at line 35 type ...
随机推荐
- Python学习第二阶段day1 内置函数,序列化,软件目录开发规范
内置函数 1.abs() 求绝对值 2.all() 所有元素为真才返回真 all( [1,1,2,3,-1] ) 值为True 3.any() 所有元素为假才返回假 any([0,0,0 ...
- Python习题之列表排序,4种方法
def sort_list_method_1(a): return sorted(a) print(sort_list_method_1([1, 4, 2])) def sort_list_metho ...
- Cmake的介绍和使用 Cmake实践
Cmake的介绍和使用 Cmake实践http://www.cppblog.com/Roger/archive/2011/11/17/160368.html
- C. Day at the Beach
codeforces 599c C. Day at the Beach One day Squidward, Spongebob and Patrick decided to go to the be ...
- nginx4win10 文件下载服务器
默认root是Nginx下目录html. 我们在其目录下新建download目录,然后在该目录下copy几个供下载的文件. 在浏览器输入http://localhost:9001/download/y ...
- RabbitMQ-rabbitmqctl和插件使用(四)
rabbitmqctl 说明 进入mq的bin目录 cd /usr/local/Cellar/rabbitmq/3.7.8/sbin ./rabbitmqctl [-n node] [-t timeo ...
- Codeforces Round #544 (Div. 3) Editorial C. Balanced Team
http://codeforces.com/contest/1133/problem/Ctime limit per test 2 secondsmemory limit per test 256 m ...
- PWA 基础学习
1.PWA 是什么? PWA 是 Progressive Web App 的缩写,从字面翻译过来就是 渐进式 Web App. 渐进式翻译过来就是慢慢的,不是一蹴而就的.这里的指的是 Wab App ...
- Android GIS开发系列-- 入门季(5) FeatureLayer加载本地shp文件与要素查询
FeatureLayer是要素图层,也是Arcgis的主要图层.用这个图层可以加载本地的shp文件.下面我们看怎样加载shp文件到MapView中.查看ArcGis API可知FeatureLayer ...
- CString、char*与string的区别
三者的区别 CString 是MFC或者ATL中的实现: string 是C++标准库中的实现: char* 为C编程中最常用的字符串指针,一般以’\0’为结束标志. string和CString均是 ...