2013-05-27 32 views
0

我目前使用Spring MVC構建webapp,其中視圖使用Apache Tiles進行呈現。我最近還添加了Spring Security。彈出版本升級後視圖解析/獲取json數據的錯誤

我正在使用彈簧版本3.0.7.RELEASE。一切正常。 因爲我需要更好的安全性,所以我不得不將它升級到更高版本。所以我升級安全到3.1.2.RELEASE和其他一切相同的版本。

之後我有問題從我的控制器獲取json數據。我的頁面的一部分被渲染,但其他調用控制器中的方法並返回json數據的部分不會呈現(它應該用接收的數據填充表格)。它拋出這個錯誤:

javax.servlet.ServletException:在servlet的與名無法解析視圖名稱爲「例如/ getJsonData /參數」「appServlet」

我調用這個方法每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) 

這裏是resloving的URL看起來怎麼樣在我的servlet上下文:

<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; 
} 

這麼說吧,我嘗試添加產生=「應用/ JSON 「並沒有改變任何東西。因此,我的問題是,在升級版本之後,我需要在配置文件中更改以繼續以相同方式使用應用程序?或者有沒有辦法讓我繼續像以前一樣使用我的應用程序?要明確一點,在升級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) 

回答

0

管理來解決這個問題。問題在於我返回了Model,它基本上只是Map,但它有一些額外的功能,這就是爲什麼春季新版本中的解析器認爲他們應該使用該結果做些事情,解決它或類似的東西。所以我改變了返回類型爲Map並添加了

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

然後返回那個resultMap。 (: 我懷疑任何人都會有同樣的問題,但你永遠不知道^^

+0

對問題有更多的信心:D目前面臨類似的事情,但試着返回json。 –

+0

哈哈哈,這就是爲什麼我寫'你永遠不知道',因爲你真的永遠不知道:DI希望這可以幫助你,或者至少給你一些提示,以解決你的問題。 – masster

+0

實際上,我實現了開箱即用的轉換,並且用我自己的轉換完成了一切工作:) –