在学习Spring注解扫描的排除方式的时候
运行test07,却在buid的时候报错
显示test05中No bean named ‘userServiceImpl’ available

applicationContext.xml中的配置:
<context:component-scan base-package="com.liu">
<!-- <context:exclude-filter type="assignable" expression="com.liu.bean.User"/>-->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
test05中对userServiceImpl进行了调用
UserService userServiceImpl = (UserService) context.getBean("userServiceImpl");
userServiceImpl.register();
将其注释掉之后test07就正常运行了
在学习Spring注解扫描并尝试排除特定bean时,遇到一个错误:在构建过程中找不到名为'userServiceImpl'的bean。通过将test05中对userServiceImpl的引用注释掉,test07得以正常运行。问题可能源于排除过滤配置。配置中使用了<context:exclude-filter>注解排除了@Service注解的bean,导致userServiceImpl未被扫描到。这提示我们,build阶段确实会处理所有方法,并依赖于正确的上下文配置。
9752

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



