[英]Spring find bean's without annotations
Can spring find implementation of interfaces without @Component
(and other) annotations on class, and without explicit bean declaration in xml? 可以在类上没有
@Component
(和其他)注释的情况下找到接口的实现,并且在xml中没有显式的bean声明吗? Just scan packages and find class that implement interface? 只需扫描包并找到实现接口的类?
From Spring doc 来自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.
默认情况下,使用@Component,@ Repository,@ Service,@ Controller注释的类或自身使用@Component注释的自定义注释是唯一检测到的候选组件。 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.
将它们添加为component-scan元素的include-filter或exclude-filter子元素。 Each filter element requires the type and expression attributes.
每个filter元素都需要type和expression属性。 The following table describes the filtering options.
下表介绍了筛选选项。
Table 3.5. 表3.5。 Filter Types
过滤类型
assignable |
可分配的| org.example.SomeClass |
org.example.SomeClass | A class (or interface) that the target components are assignable to (extend/implement).
目标组件可分配给(扩展/实现)的类(或接口)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.