最近新看到自动注入Bean,翻起以前的项目看了下。
以前我们使用注解的的配置
<context:component-scan
这种需要使用繁琐的注解。
自动注解配置:
<!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
<context:component-scan base-package="com.zucp.ciap">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>这样每个Bead就不必都去写繁琐的注解。
context:exclude-filter标签的含义是:排除扫描到的所有类,不纳入Spring容器中。

本文探讨了Spring框架中使用自动扫描组件和排除特定注解的配置方法,旨在减少繁琐的注解使用,提升开发效率。通过配置<context:component-scan>元素,并结合<exclude-filtertype>标签排除@Controller和@ControllerAdvice类,实现自动注册Bean而不必为每个Bean手动添加注解。
969

被折叠的 条评论
为什么被折叠?



