我目前正在開發Spring MVC項目,並且使用"<MVC:resource "
標籤SpringMVC加載靜態資源。於是我下載了springMVC展示項目,並對其進行了一些更改以檢查此標記。如何解決Spring MVC展示項目的「<resources」標籤和「<context:component-scan ..」標籤之間的衝突
由於我的項目是一個簡單的,在我看來,「conversionservice」的兩個標籤是沒有必要的。
但是,我刪除了這兩個標籤後,發生了一些有線事件。 如果我同時爲靜態資源"<resources mapping="/resources/.."
和"<context:component-scan base-package="org.springframework.samples.mvc" />"
標記(在controllers.xml中)配置標記,那麼我無法訪問在控制器上附加的任何uri - 它會返回404未找到的錯誤。如果我註釋掉資源映射標籤,那麼這些控制器工作正常。
任何人都曾經歷過這種情況?任何想法如何解決這個問題?
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven conversion-service="conversionService">
<argument-resolvers>
<beans:bean class="org.springframework.samples.mvc.data.custom.CustomArgumentResolver"/>
</argument-resolvers>
</annotation-driven>
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources/ directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<!-- Only needed because we install custom converters to support the examples in the org.springframewok.samples.mvc.convert package -->
<beans:bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<beans:property name="formatters">
<beans:bean class="org.springframework.samples.mvc.convert.MaskFormatAnnotationFormatterFactory" />
</beans:property>
</beans:bean>
<!-- Imports user-defined @Controller beans that process client requests -->
<beans:import resource="controllers.xml" />
</beans:beans>
最後在添加標籤「 」之後,現在一切正常。仍然不確定背後的原因。只是在這裏記錄,所以有人有同樣的問題可以節省他們的時間。 –
你需要告訴我們你的控制器映射。 – soulcheck