其他分享
首页 > 其他分享> > Spring查找没有注释的bean

Spring查找没有注释的bean

作者:互联网

Spring是否可以找到在类上没有@Component(和其他)注释且在xml中没有显式bean声明的接口实现?只是扫描软件包并找到实现接口的类?

解决方法:

Spring doc

By default, classes annotated with @Component, @Repository, @Service,
@Controller, or a custom annotation that itself is annotated with
@Component are the only detected candidate components. However, you
can modify and extend this behavior simply by applying custom filters.
Add them as include-filter or exclude-filter sub-elements of the
component-scan element. Each filter element requires the type and
expression attributes. The following table describes the filtering
options.

表3.5.筛选器类型

assignable | org.example.SomeClass | A class (or interface)
that the target components are assignable to (extend/implement).

标签:dependency-injection,spring,inversion-of-control
来源: https://codeday.me/bug/20191121/2050191.html