applicationContext.xml
<!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
<context:component-scan base-package="com.dudu" use-default-filters="true">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
springmvc.xml
<!-- spring-mvc为子容器,applicationContext.xml为spring父容器,子容器创建的service是没有事务处理能力的,所以service要放在父容器中创建,用context:exclude-filter过滤掉 -->
<context:component-scan base-package="com.dudu" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>