سؤال

I'm currently building webapp using Spring MVC, where view is rendered with Apache Tiles. I recently also added Spring Security.

I was working with spring version 3.0.7.RELEASE. And everything worked fine. Because I needed better security I had to upgrade it to higher versions. So i upgraded security to 3.1.2.RELEASE and everything else to same version.

After that I have problem with fetching json data from my controller. Part of my page is rendered, but other part that calls method in controller and should get json data back doesn't render (it should fill table with data it receives). It throws this error:

javax.servlet.ServletException: Could not resolve view with name 'example/getJsonData/parameter' in servlet with name 'appServlet'

I'm calling this method every 5s from my jsp, using jQuery GET method like this:

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

And when I check console to see what's happening I see this:

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

Here is how resloving urls look like in my servlet-context:

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

And here is how method in my controller looks like

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

Let's just say I tried adding produces="application/json" and didn't change anything. So my Q her is, what do I need to change in my configuration files after upgrading version to continue using the app in same way? Or is there a way for me to continue to use my app same way as before? Just to be clear, everything worked before upgrading Spring versions.

Here is complete stacktrace for error:

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)
هل كانت مفيدة؟

المحلول

Manage to solve the issue. Problem was that I was returning Model, which basically is just Map, but it has some extra features and that's why resolvers in newer versions of spring thought they should do something with that result, resolve it or something like that. So I changed return type to Map and added

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

And then returned that resultMap. (: I doubt that anyone will have the same problem, but you never know ^^

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top