發現映射我使用Spring MVC與Spring 3.1彈簧MVC中,沒有在DispatcherServlet的,基本包註解
我放置在applicationContext.xml所有基包自動組件掃描。然而,當我嘗試這一點,即時得到錯誤:
No mapping found for HTTP request with URI [/Test1/] in DispatcherServlet with name 'test'
我通過在測試servlet.xml中添加控制器封裝解決上述錯誤
<context:component-scan base-package="com.george.controller" />
爲什麼我一定要明確添加test-servlet.xml中的控制器包,當我已經將所有包添加到applicationContext.xml中時?
的web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/applicationContext.xml
/WEB-INF/spring/dataContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
的applicationContext.xml
<context:annotation-config />
<context:component-scan base-package="com.george.dao, com.george.service, com.george.controller" />
<aop:aspectj-autoproxy />
<tx:annotation-driven transaction-manager="transactionManager" />
測試servlet.xml中
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>