springmvc启动报错, No mapping found for HTTP request with URI
我搭建springmvc工程,我想拦截所有的请求,在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">
<display-name>spring-mvc-demo</display-name>
<!-- 加载springMVC配置 -->
<servlet>
<servlet-name>springServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/resourceNotFound</location>
</error-page>
</web-app>
spring-config.xml配置
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
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.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd"
default-autowire="byName">
<!-- 加载属性文件 -->
<bean class="com.jd.springmvc.demo.common.spring.CustomizedPropertyConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>classpath*:${global.config.important}</value>
<value>classpath*:${global.config.diffInEnvs}</value>
<!--<value>classpath:auth.properties</value>-->
<value>classpath:common.properties</value>
</list>
</property>
</bean>
<!-- 自动注入ApplicationContext -->
<bean class="com.jd.springmvc.demo.common.spring.ApplicationContextUtil"/>
<!-- 注解扫描包 -->
<context:component-scan base-package="com.jd.springmvc.demo.web" />
<!-- 导入分类配置 -->
<import resource="classpath*:spring/spring-config-mvc.xml" />
<import resource="classpath*:spring/spring-config-service.xml" />
<import resource="classpath*:spring/spring-config-dao.xml" />
<!--<import resource="classpath*:spring/spring-config-rpc.xml" />-->
<!--<import resource="classpath*:spring/spring-config-jsf.xml" />-->
<!--<import resource="classpath*:spring/spring-config-signin.xml"/>-->
<!--<import resource="classpath*:spring/spring-config-jmq.xml"/>-->
<!--<import resource="classpath*:spring/spring-config-redis.xml"/>-->
</beans>
spring-config-mvc.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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"
default-autowire="byName">
<!-- 添加MVC注解模式 -->
<mvc:annotation-driven/>
<!-- 映射静态资源 -->
<mvc:resources location="/WEB-INF/statics/" mapping="/resource/**"/>
<!--<mvc:resources location="/WEB-INF/publish/" mapping="/publish/**"/>-->
<!--<mvc:default-servlet-handler/>-->
<!-- 视图解析器配置 -->
<bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/vm/" />
<property name="configLocation" value="classpath:velocity.properties" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="suffix" value=".vm" />
<property name="contentType" value="text/html;charset=UTF-8" />
</bean>
<!--<!– 文件上传 –>-->
<!--<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">-->
<!--<property name="defaultEncoding" value="UTF-8"/>-->
<!--</bean>-->
</beans>
启动的时候,报错:
No mapping found for HTTP request with URI [/resourceNotFound] in DispatcherServlet with name 'springServlet'
请问是什么原因?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你给配的404页面不存在吧,指向一个已存在的静态页面,或controller中配上/resourceNotFound试试