【发布时间】:2011-05-20 20:40:38
【问题描述】:
我正在创建一个基于 3.1 M1 的新项目作为测试用例。我将 web.xml 设置为使用 DispatcherServlet,其 contextClass 为 org.springframework.web.context.support.Annotation ConfigWebApplicationContext, contextConfigLocation 为 domain.ApplicationConfiguration。
但是,当我的一个 @Controller 注释类中的方法尝试返回视图名称为“test”的 ModelAndView 时,它会在同一控制器类中查找 @RequestMapping 为“test”的方法我希望它在 WebContent 目录中查找名为“test.jsp”的 jsp,并且看起来没有任何 viewresolver 永远不会被实例化。我尝试在 ApplicationConfiguration 类中声明一个视图解析器,但它似乎被忽略了。 我总是收到类似以下的日志消息: 警告:在名称为“dispatcher”的 DispatcherServlet 中找不到带有 URI [/test/foo/test] 的 HTTP 请求的映射
如何在 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>
还有哪些其他配置有用?
【问题讨论】:
标签: java spring spring-mvc