Defining a resolving view in Spring 3.1

I am creating a new project based on 3.1 M1 as a test case. I have my web.xml configured to use DispatcherServlet with the context class org.springframework.web.context.support.Annotation ConfigWebApplicationContext and contextConfigLocation domain.ApplicationConfiguration.

However, when a method from one of the annotated @Controller classes with attempts to return a ModelAndView with a name of the form "test" I, it searches for a method in the same controller class with @RequestMapping "test" when I would like it to look for jsp with the name " test.jsp "in the WebContent directory, and it looks like the viewresolver is never created. I tried declaring a view recognizer in the ApplicationConfiguration class, but it seems to be ignored. I always get a message in the log: WARNING. There is no mapping for an HTTP request with a URI [/ test / foo / test] in a DispatcherServlet named "dispatcher"

How to configure the recognizer in 3.1?

web.xml

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <context-param> <param-name>contextClass</param-name> <param-value> org.springframework.web.context.support.AnnotationConfigWebApplicationContext </param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>domain.test.configuration.ApplicationConfiguration</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextClass</param-name> <param-value> org.springframework.web.context.support.AnnotationConfigWebApplicationContext </param-value> </init-param> <init-param> <param-name>contextConfigLocation</param-name> <param-value>domain.test</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <display-name>test</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app> 

What other parts of the configuration will be useful?

+4
source share
3 answers

From the documentation, the usual way to define a JSP viewResolver is:

 <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> 
+2
source

It started working when I changed the tag: http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "id =" WebApp_ID "version =" 3.0 ">

so that: http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "version =" 2.5 ">

I know that servlet 3.0 support was supposed to appear in Milestone 2, I just did not expect such a failure to proactively announce it. I did not get any errors, he simply ignored all my controller mappings.

+1
source
 <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> 

Do not specify the Url pattern as /* . Specify the Url template as *.htm . Of course it will work.

+1
source

All Articles