- 在使用spring mvc初始化项目的时候,我用jprofile监控查看内存信息的时候,发现每个bean的实例数都是2个。
查看springmvc的配置文件
<context:component-scan base-package="com.refordom" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
本来我的想法是这里面只扫描@COntroller注解的bean,其他的都不扫描。但是事实是使用其他的注解的bean也没扫描到了,所以在这里又初始化了一次。
解决办法:
发现这里有一个use-default-filters配置,默认为true,将这个配置改成false,即可解决这个问题。
spring配置:
<context:component-scan base-package="com.refordom">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>