问题描述:
先说下开发环境和jar包
用的是eclipse : Neon.1a Release , JAVA JDK1.8,JAR包:spring-xxxx.4.3
spring-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:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/mvc
<span style="white-space:pre"> </span>http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.tjs.trade.about.controller" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml部分代码
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:resources/spring/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:resources/spring/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
问题是:tomcat启动后通过url请求后台:
org.springframework.web.servlet.PageNotFound noHandlerFound
警告: No mapping found for HTTP request with URI [/prjName/controllerxxx] in DispatcherServlet with name 'spring'
怀疑这里[/prjName/controllerxxx]把prjName也作为controller的requestMapping("")里的参数处理了,它提示没有找到这个映射,但为什么不是提示controllerxxx没找到呢,而把项目名也带上一起映射了,可能是web project setting里项目的命名空间配置成“/”了,这是一种可能
问题找到了,spring-servlet.xml和applicationContext.xml启动的时候根本就没加载
启动没报任何错,记得第一次配置好的时候,这两个文件的路径没设置对,后来设置对了,然后启动没被加载直接过了,我把这两个文件复制到外边,然后把项目里的删了再考进来,没问题了,对!就是备份一下源文件,删了再拷回来就没问题了,我只想说太坑了。。。。。