Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? Just scan packages and find class that implement interface?

like image 311
Ruslan Avatar asked Feb 05 '26 07:02

Ruslan


1 Answers

From 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.

Table 3.5. Filter Types

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

like image 123
Xstian Avatar answered Feb 09 '26 03:02

Xstian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!