0

我目前正在使用 Spring MVC 构建 webapp,其中视图是使用 Apache Tiles 呈现的。我最近还添加了 Spring Security。

我正在使用春季版本3.0.7.RELEASE。一切正常。因为我需要更好的安全性,所以我不得不将它升级到更高版本。所以我将安全性升级到3.1.2.RELEASE并将其他所有内容升级到相同版本。

之后,我从控制器获取 json 数据时遇到问题。我的页面的一部分被渲染了,但是在控制器中调用方法并且应该返回 json 数据的其他部分没有渲染(它应该用它接收到的数据填充表)。它抛出这个错误:

javax.servlet.ServletException:无法解析名称为“appServlet”的 servlet 中名称为“example/getJsonData/parameter”的视图

我每隔 5 秒从我的 jsp 调用这个方法,使用这样的 jQuery GET 方法:

function update() {
      $.getJSON('./example/getJsonData/parameter', function(data) {
        //do some things            
        }); 
  };

当我检查控制台以查看发生了什么时,我看到了:

GET http://localhost:8080/myapp/example/getJsonData/parameter - 500 (Internal Server Error)

这是我的 servlet-context 中重新处理的 url 的样子:

<beans:bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <beans:property name="viewClass">
        <beans:value>
            org.springframework.web.servlet.view.tiles2.TilesView
        </beans:value>
    </beans:property>
</beans:bean>
<beans:bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <beans:property name="definitions">
        <beans:list>
            <beans:value>/WEB-INF/tiles/general.xml</beans:value>
        </beans:list>
    </beans:property>
</beans:bean>

这是我的控制器中的方法的样子

@RequestMapping(value = "getJsonData/{parameter}", method = RequestMethod.GET)
public @ResponseBody
Model getJsonData(HttpSession httpSession, Model model, @PathVariable(value = "parameter") String parameter) {
model.addAttribute("parameter", true);
//doing something here
    return model;
}

假设我尝试添加 products="application/json" 并没有改变任何东西。所以我的Q她是,升级版本后我需要在我的配置文件中进行什么更改才能继续以相同的方式使用该应用程序?或者有没有办法让我像以前一样继续使用我的应用程序?需要明确的是,在升级 Spring 版本之前一切正常。

这是错误的完整堆栈跟踪:

27.05.2013. 12:52:57 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet appServlet threw exception
javax.servlet.ServletException: Could not resolve view with name 'example/getJsonData/parameter' in servlet with name 'appServlet'
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1190)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:816)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)
4

1 回答 1

0

设法解决问题。问题是我返回了 Model,它基本上只是 Map,但它有一些额外的特性,这就是为什么新版本的 spring 中的解析器认为他们应该对这个结果做一些事情,解决它或类似的事情。所以我将返回类型更改为 Map 并添加

 Map<String, Object> resultMap = new HashMap<String, Object>(model.asMap());

然后返回那个resultMap。(:我怀疑有人会遇到同样的问题,但你永远不知道^^

于 2013-06-03T13:06:04.357 回答