This is my 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_2_5.xsd" version="2.5">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
and this is my dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
开发者_运维知识库<!-- JSR-303 support will be detected on classpath and enabled automatically -->
<mvc:annotation-driven/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
And I have an annotated Controller class:
@Controller
public class MainController {
@RequestMapping("/test")
public ModelAndView testHandler(){
ModelAndView mav = new ModelAndView();
mav.setViewName("testView");
mav.addObject("message", "test");
return mav;
}
}
The project compiles without errors, but when I run it and hit http://.aggengine.com//test I get a 404. Is my mapping wrong or my URI?
I think you forgot to create a <bean>
for your controller.
<mvc:annotation-driven/>
Just enables support for reading the annotations off of beans when they're created.
E.g. To register your controller:
<bean id="mainController" class="my.package.MainController"/>
Alternatively you could enable automatic classpath scanning, but that can cause performance issues on appengine as it's slow (and will happen every time your app cold-starts)
To enable classpath scanning, add the context namespace to your <beans>
and add:
<context:component-scan base-package="my.package"/>
精彩评论