1

component-scan を spring-common.xml に入れても、Spring MVC がコントローラーを見つけられないのはなぜですか?しかし、component-scan を springMVC-servlet.xml に入れれば、機能します。

web.xml

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:spring/spring-*.xml</param-value>
</context-param>


<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


<!-- Spring MVC -->
<servlet>
    <servlet-name>springMVC</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/springMVC-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>springMVC</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

springMVC-servlet.xml

<mvc:annotation-driven />


<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="order" value="2" />
    <property name="prefix" value="/WEB-INF/view/" />
    <property name="suffix" value=".html" />
</bean>

<!-- 对静态资源文件的访问 -->
<mvc:resources mapping="/js/**" location="/static/js/" />
<mvc:resources mapping="/css/**" location="/static/css/" />
<mvc:resources mapping="/image/**" location="/static/image/" />
<mvc:default-servlet-handler />

spring-common.xml

<context:component-scan base-package="com.wind">
</context:component-scan>

4

1 に答える 1