1.在springmvc配置文件中扫描bean的时候。只扫描包含@controller。因为既然要和spring整合,那么springmvc还是专心做web请求的转发吧。
2.在spring配置文件中去掉@controller的扫描。其他bean都是单例的,在容器启动的时候,一起初始花了。
最后,其实单独使用 springmvc也是可以的。让他管理所有bean.
1 在主容器中(applicationContext.xml),将Controller的注解打消掉
- <context:component-scan base-package="com">
- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
- </context:component-scan>
2 而在springMVC配置文件中将Service注解给去掉
- <context:component-scan base-package="com">
- <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
- </context:component-scan>