Constructor injection is one of the ways to inject dependencies into a bean using its constructor parameters. Since Spring 4.3, if a bean has only one constructor, the @Autowired annotation can be omitted and Spring will use that constructor by default.
Constructor injection is generally recommended over field injection because it makes the dependencies of a bean explicit and immutable. It also facilitates unit testing because it allows us to easily provide mock dependencies through constructor arguments.
Questions # 23:
Which two statements are true regarding bean creation? (Choose two.)
Options:
A.
A Spring bean can be explicitly created by annotating methods or fields by @Autowired.
B.
A Spring bean can be implicitly created by annotating the class with @Component and using the component-scanner to scan its package.
C.
A Spring bean can be implicitly created by annotating the class with @Bean and using the component- scanner to scan its package.
D.
A Spring bean can be explicitly created using @Bean annotated methods within a Spring configuration class.
E.
A Spring bean can be explicitly created by annotating the class with @Autowired.