我正在創建一個基於3.1 M1的新項目作爲測試用例。我有我的web.xml設置使用DispatcherServlet具有org.springframework.web.context.support.Annotation ConfigWebApplicationContext的contextClass和domain.ApplicationConfiguration的contextConfigLocation。在Spring 3.1中定義視圖解析器
但是,當從我的@Controller註釋類之一嘗試返回帶有視圖名稱「test」的ModelAndView的方法時,它會在同一控制器類中使用@RequestMapping的「test」當我希望它在WebContent目錄中尋找一個名爲「test.jsp」的jsp時,它看起來沒有viewresolver永遠不會實例化。我曾嘗試在ApplicationConfiguration類中聲明一個視圖解析器,但它似乎被忽略。 我總是得到一個日誌消息是這樣的: 警告:沒有映射的DispatcherServlet發現HTTP請求與URI [/測試/富/測試]名爲「調度」
如何配置在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>
什麼配置的其他部分將是有益的?
這將需要創建一個servletName.xml文件,這在3.1中不再需要。您應該能夠使用註釋進行所有配置,其中所需的唯一xml文件是web.xml文件。 – 2011-05-24 22:39:47