Sunday, September 12, 2021

What if there is multiple implementation of a interface which is using in @Autowired ?

If there is multiple implementation of an interface then we need to specify which one's implementation will use. For that reason we need to specify @Primary in the implemented class or we can use autowired by name .But @Primary annotation have the highest precedence than autowired by name.

Another approach is we can use @Qualifier("name") over the name of the implement class .We then should use this @Qualifier("name") over the injected interface.

No comments:

Post a Comment

Testing controller

------Controller------------- @RestController @RequestMapping("/items") public class ItemController {     private final ItemServic...