我这里的报错实际情况是:
14:02:15,736 WARN [PageNotFound] No mapping found for HTTP request with URI [/spring3MVC/abc/index.do] in DispatcherServlet with name 'spring3MVC'
其中,[spring3MVC/abc/index.do]是我请求的路径,就我现在的项目,我的请求路径是:
http://localhost:8080/spring3MVC/abc/index.do
spring3MVC是我的项目名,abc是action的注解用的,index是方法的注解
@Controller
@RequestMapping("/abc")
public class ZhujieRequestController {
protected final transient Log log = LogFactory.getLog(ZhujieRequestController.class);
@RequestMapping("/index")
public String index() {
return "hello";
}
}
其它的配置文件,比如web.xml和一些jdbc连接的我就不说了,就说核心xml文件:spring3MVC-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!--自动扫描的包名 -->
<context:component-scan base-package="com.ideawu" />
<!-- 默认的注解映射的支持 -->
<!-- <mvc:annotation-driven /> -->
<!-- 视图解释类 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
<!--
可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑
-->
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
</bean>
<!-- 通过注解请求action里面的方法-->
<bean id="annotationHandlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="0" />
<property name="useDefaultSuffixPattern" value="false" /><!--请注意这里,value="false",就因为这个false,我从早上8点,弄到下午2点-->
</bean>
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
</beans>
基本配置就是这样,服务重启了好多变,总是不行,后来,我把
<property name="useDefaultSuffixPattern" value="false" />
的value改为true,就正常了。 哎,我也是刚学,碰到这个问题。 还好运气好,搞定了