Which two statements about the @Autowired annotation are true? (Choose two.)
Which two statements about the @Autowired annotation are true? (Choose two.)
The @Autowired annotation in Spring can be used to inject dependencies into fields, methods, and constructors. Fields with @Autowired are injected after the construction of the bean, but before any config methods are invoked. This ensures that all dependencies are available for the configuration methods. Additionally, the @Autowired annotation supports multiple arguments in a method, allowing for flexible method-level dependency injection.
B is of course correct, but the reason why C is correct is because the default required setting of Autowired is 'true'. If no bean is found, a org.springframework.beans.factory.NoSuchBeanDefinitionException is thrown, which is a RuntimeException.
A is not correct as the Fields are injected right after construction of a bean, before any config methods are invoked. D is incorrect as you can't annotate a class. E is incorrect as Autowired is not supported in BeanPostProcessor or BeanFactoryPostProcessor, so you can't inject a reference in them using Autowired. Here is my reference: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/factory/annotation/Autowired.html
B and C
E is not correct Note that actual injection is performed through a BeanPostProcessor which in turn means that you cannot use @Autowired to inject references into BeanPostProcessor or BeanFactoryPostProcessor types. Please consult the javadoc for the AutowiredAnnotationBeanPostProcessor class (which, by default, checks for the presence of this annotation). https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/factory/annotation/Autowired.html
The others seem wrong
B and C
A and B, per Autowired documentation. Autowired Fields Fields are injected right after construction of a bean, before any config methods are invoked. Such a config field does not have to be public. Autowired Methods Config methods may have an arbitrary name and any number of arguments; each of those arguments will be autowired with a matching bean in the Spring container. Bean property setter methods are effectively just a special case of such a general config method. Such config methods do not have to be public.
Not sure about A, because @Autowired fields are injected before any config methods (@Bean, @Component, @Configuration, etc..) are invoked.