com.fasterxml.jackson.databind.JsonMappingException: ApplicationObjectSupport instance [org.springframework.web.servlet.view.json.MappingJackson2JsonView: unnamed] does not run in an ApplicationContext (through reference chain: java.util.HashMap["modelAndView"]->org.springframework.web.servlet.ModelAndView["view"]->org.springframework.web.servlet.view.json.MappingJackson2JsonView["applicationContext"])
jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>RequestAttribute test</title>
</head>
<body>
<%
request.setAttribute("id", 84L); request.getRequestDispatcher("/attribute/requestAttribute.do").forward (request, response);
%>
</body>
</html>
和控制器代码:
@Controller
@RequestMapping("/attribute")
public class Attribute {
@Autowired
private RoleService roleService = null;
@RequestMapping("/requestAttribute")
public ModelAndView reqAttr( @RequestAttribute("id") Long id) {
ModelAndView mav= new ModelAndView();
Role role = roleService.getRole(id);
mav.addObject("role", role);
mav.setView(new MappingJackson2JsonView());
return mav;
}
}
和异常输出:
HTTP状态500 –内部服务器错误
类型异常报告
消息在第[12]行处理[/WEB-INF/views/attr.jsp]时发生了异常
说明服务器遇到意外状况,阻止其满足请求。
例外
java.io.IOException:在第[12]行处理[/WEB-INF/views/attr.jsp]时发生了异常
9: 10:<% 11:request.setAttribute(“ id”,84L); 12:> request.getRequestDispatcher(“ / attribute / requestAttribute.do”)。forward(request,response); 13:%> 14: 15:
Stacktrace: org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:504) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:304) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 根本原因
com.fasterxml.jackson.databind.JsonMappingException:ApplicationObjectSupport实例[org.springframework.web.servlet.view.json.MappingJackson2JsonView:未命名]不在ApplicationContext中运行(通过参考链:java.util.HashMap [“ modelAndView“]-> org.springframework.web.servlet.ModelAndView [” view“]-> org.springframework.web.servlet.view.json.MappingJackson2JsonView [” applicationContext“]) com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:394) com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:353) com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316) com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:727) com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727) com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:722) com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:643) com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:33) com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) com.fasterxml.jackson.databind.ObjectWriter $ Prefetch.serialize(ObjectWriter.java:1396) com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:913) org.springframework.web.servlet.view.json.AbstractJackson2View.writeContent(AbstractJackson2View.java:211) org.springframework.web.servlet.view.json.AbstractJackson2View.renderMergedOutputModel(AbstractJackson2View.java:160) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:304) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.apache.jsp.WEB_002dINF.views.attr_jsp._jspService(attr_jsp.java:126) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:304) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 根本原因
java.lang.IllegalStateException:ApplicationObjectSupport实例[org.springframework.web.servlet.view.json.MappingJackson2JsonView:未命名]未在ApplicationContext中运行 org.springframework.context.support.ApplicationObjectSupport.getApplicationContext(ApplicationObjectSupport.java:141) sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:688) com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727) com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:722) com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:643) com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:33) com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) com.fasterxml.jackson.databind.ObjectWriter $ Prefetch.serialize(ObjectWriter.java:1396) com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:913) org.springframework.web.servlet.view.json.AbstractJackson2View.writeContent(AbstractJackson2View.java:211) org.springframework.web.servlet.view.json.AbstractJackson2View.renderMergedOutputModel(AbstractJackson2View.java:160) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:304) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.apache.jsp.WEB_002dINF.views.attr_jsp._jspService(attr_jsp.java:126) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:304) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)