Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Autowire default mode

How does Spring @Autowire beans: byName or byType? If one is not possible, is a second trial done using another mode?


2 Answers

If annotated with @Autowired it will inject the bean with the matching type (An exception will be thrown if there are more than one of a type). To specify a name use the @Qualifier annotation.

like image 82
Wilhelm Kleu Avatar answered Sep 09 '25 23:09

Wilhelm Kleu


Springs @Autowire wires by type. For wiring by name you can also use

@Resource(name = "id")
like image 36
Daff Avatar answered Sep 09 '25 21:09

Daff