The injection point has the following annotations:

The injection point has the following annotations:

  • @Autowired
  • @Qualifier

The @Autowired annotation is used in Spring to automatically wire dependencies when a bean is created. It allows for automatic dependency injection. The annotation can be used on fields, constructors, or setter methods. When Spring encounters a bean with the @Autowired annotation, it will try to find a matching bean to inject.

For example, consider a service class with an interface dependency:

@Service
public class MyService {
    private final MyRepository repository;
    
    // Constructor injection with @Autowired
    @Autowired
    public MyService(@Qualifier("myRepositoryImpl") MyRepository repository) {
        this.repository = repository;
    }
    
    // Other methods and business logic
}

In this example, the @Autowired annotation is used on the constructor of the MyService class to inject the MyRepository bean. The @Qualifier annotation is used to specify a particular bean if there are multiple matching beans.

Read more interesting post

Leave a comment