Junior — Middle
Can you list the annotations used for automatic configuration of components or dependencies in an application?
sobes.tech AI
Answer from AI
In Java, the following annotations are often used for automatic component configuration and dependency injection (especially in the Spring Framework):
@Component— marks a class as a component that will be automatically detected and registered in the context.@Service— a specialized version of@Componentfor the service layer.@Repository— a specialized version of@Componentfor the data access layer.@Controller— for controllers in MVC.@Autowired— for automatic dependency injection by type.@Qualifier— specifies which bean to inject if there are multiple.@Configuration— a class containing bean definitions.@Bean— a method that creates and returns a bean.@ComponentScan— specifies packages to scan for components.
Example:
@Component
public class UserService {
@Autowired
private UserRepository userRepository;
// ...
}