B. If an embedded database is on the classpath, it will be used to configure a DataSource by default.
This is true because the @DataJpaTest annotation enables auto-configuration of an embedded database if one is available on the classpath, such as H2, HSQLDB, or Derby. This allows the test to run with a temporary and isolated database that can be configured with test data.
D. It auto-configures a TestEntityManager bean.
This is true because the @DataJpaTest annotation provides a TestEntityManager bean that can be used to perform common JPA operations in the test. The TestEntityManager is an alternative to the standard EntityManager that provides some convenience methods and exception translation.
Which two statements are true concerning constructor injection? (Choose two.)
Options:
A.
If there is only one constructor the @Autowired annotation is not required.
B.
Constructor injection only allows one value to be injected.
C.
Constructor injection is preferred over field injection to support unit testing.
D.
Construction injection can be used with multiple constructors without @Autowired annotation.
E.
Field injection is preferred over constructor injection from a unit testing standpoint.
Answer:
A, C
Explanation:
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.
Question 3
Which two statements are correct regarding Spring Boot auto-configuration customization? (Choose two.)
Options:
A.
Use the @AutoConfigureAfter or @AutoConfigureBefore annotations to apply configuration in a specific order.
B.
Disable specific auto-configuration classes by using the exclude attribute on the
@EnableAutoConfiguation annotation.
C.
Provide customized auto-configuration by subclassing the provided Spring Boot auto-configuration classes.
D.
Enable component scanning within auto-configuration classes to find necessary components.
E.
Control the order of auto-configuration classes applied with @AutoConfigureOrder.