开发者

What's the purpose of <context:exclude-filter> when applied to a Spring MVC controller package configuration?

<context:exclude-filter type="aspectj" expression="com.myapp.controller.*"/>

What's the purpose of the line above in the applicationContext.xml file below which is used to configure a Spring MVC web app?

<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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:annotation-config />
    <context:component-scan base-package="com.myapp">
        <context:exclude-filter type="aspectj" expression="com.myapp.controller.*"/>
    </context:component-开发者_运维技巧scan>

    <import resource="applicationContext-data.xml" />
    <import resource="applicationContext-security.xml" />
    <import resource="applicationContext-service.xml" />

</beans>


This is adding on top of what @Luciano has said, typically a good practice for a Spring-MVC application is to keep the Spring core context configuration(loaded by ContextLoaderListener) and the presentation tier configuration(loaded via DispatcherServlet) separate. In this specific instance what you have shown is the core context file which is explicitly excluding the controllers, which would likely have been explicitly defined along with your DispatcherServlet loaded Spring configuration file.


It will tell Spring to exclude the components (Spring annotated classes) that may be present in the com.myapp.controller package and subpackages. Maybe there are controllers that the responsible for this web app doesn't want to be activated.

The rest of the components located under com.myapp will be loaded and set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜