启动tomcat,访问web应用报如下错误:
[org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI [/v20/activity/test/] in DispatcherServlet with name 'appServlet'
springmvc配置如下:
<bean id="handlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
<property name="messageConverters">
<list>
<bean id="utf8StringHttpMessageConverter" class=" com.app.chang.anlynis.utils.UTF8StringHttpMessageConverter" />
</list>
</property>
</bean>
<!-- 扫描所有的controller 但是不扫描service-->
<context:component-scan base-package="com.app.chang.anlynis">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>
<mvc:annotation-driven />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/jsp directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 启用基于注解的处理器映射,添加拦截器,类级别的处理器映射 -->
<mvc:interceptors>
<bean class="com.app.chang.anlynis.utils.HandlerInterceptor" />
</mvc:interceptors>
<!--
配置一个基于注解的定制的WebBindingInitializer,解决日期转换问题,方法级别的处理器映射,
有人说该bean要放在context:component-scan前面,要不然不起作用,但我试的放后面也可以啊。
-->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="cacheSeconds" value="0" />
<property name="webBindingInitializer">
<bean class="com.app.chang.anlynis.utils.MyWebBinding" />
</property>
</bean>
</beans>
web.xml配置如下:
<display-name>v20</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- The dataBase definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/root-context.xml</param-value>
</context-param>
<!-- validate code -->
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 获得线程绑定的request -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 著名 Character Encoding filter -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 浏览器不支持put,delete等method,由该filter将?_method=delete转换为标准的http delete方法 -->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<servlet-name>appServlet</servlet-name>
</filter-mapping>
<!-- 返回码加载 -->
<servlet>
<servlet-name>ReturnDecriptionServlet</servlet-name>
<servlet-class>com.app.chang.anlynis.controller.system.SystemServlet</servlet-class>
<!-- 启动顺序 -->
<load-on-startup>20</load-on-startup>
</servlet>
</web-app>
controler如下:
@Controller
@RequestMapping("/activity")
public class ActivityController extends BaseController {
@RequestMapping(value = "/test", method = RequestMethod.POST)
public String test(Model model) throws Exception {
return "test";
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。