The _____ annotation in Spring Data JPA can be used to eagerly fetch the associated entities from the database.

  • @EagerFetch
  • @Fetch
  • @FetchType.EAGER
  • @Fetch.EAGER
The @FetchType.EAGER annotation in Spring Data JPA can be used to eagerly fetch the associated entities from the database. When an entity is loaded, all its associations marked with FetchType.EAGER are fetched immediately along with the main entity, reducing the number of database queries. However, you should use this option judiciously as it can lead to performance issues if overused.

Which annotation is predominantly used in Spring Boot to write a JUnit test for a class?

  • @Autowired
  • @RunWith
  • @SpringBootTest
  • @Test
In Spring Boot, the @Test annotation is predominantly used to indicate that a method is a JUnit test method. It marks the method as a test to be run by the JUnit framework.

In JUnit, _____ tests allow you to run the same test multiple times with different arguments.

  • Iterative
  • Loop
  • MultiTest
  • Parameterized
In JUnit, Parameterized tests allow you to run the same test method multiple times with different sets of input arguments. This is useful for testing the same logic with various input values and ensuring that it behaves correctly for all cases.

How do you configure a cache manager in Spring Boot?

  • By adding the @Cacheable annotation to methods that should be cached.
  • By modifying the 'application.properties' file with cache settings.
  • By creating a custom caching class and injecting it into services.
  • By disabling caching entirely in the Spring Boot application.
In Spring Boot, cache manager configuration is typically done by modifying the 'application.properties' file with cache-related settings. Spring Boot provides easy-to-use properties for configuring popular caching solutions like EhCache, Caffeine, and more. The other options are not the standard way to configure a cache manager in Spring Boot.

How can you create a custom query method in a Spring Data JPA repository?

  • By defining a method with a specific naming convention.
  • By using a native SQL query.
  • By annotating a method with @Query and providing the JPQL query.
  • By creating a new repository interface for custom queries.
In Spring Data JPA, you can create custom query methods by defining a method in your repository interface with a specific naming convention. Spring Data JPA generates the query based on the method name, eliminating the need to write explicit queries. The other options represent alternative ways to create custom queries but are not the typical approach in Spring Data JPA.

In Spring, the _____ annotation is used to indicate that a method should be invoked after the bean has been constructed and injected.

  • @PostConstruct
  • @Autowired
  • @BeanPostProcessor
  • @Inject
In Spring, the @PostConstruct annotation is used to indicate that a method should be invoked after the bean has been constructed and injected. It is commonly used for initialization tasks that need to be performed after the bean's dependencies have been injected. The other options, such as @Autowired, @BeanPostProcessor, and @Inject, serve different purposes and are not used for the same scenario.

How can you encrypt and decrypt property values in Spring Boot to secure sensitive information?

  • By using the @EncryptProperty annotation.
  • By configuring property encryption in application.properties.
  • By using the spring.security module for encryption.
  • By using the Jasypt library and configuring it in application.properties.
To encrypt and decrypt property values in Spring Boot, you can use the Jasypt library and configure it in the application.properties file. This library provides a straightforward way to secure sensitive information such as database passwords. While there are other security-related options in Spring Boot, the Jasypt library is commonly used for property encryption.

In what scenarios would you choose to implement a custom validator instead of using the standard Bean Validation annotations?

  • When you need to perform complex validation logic that can't be expressed using standard annotations.
  • When you need to validate simple data types like integers and strings.
  • When you want to achieve better performance in your application.
  • When you want to minimize the use of custom code in your application.
Custom validators are preferred when complex validation logic is required, which can't be achieved with standard Bean Validation annotations. While standard annotations are suitable for many cases, custom validators are necessary for scenarios where specific and intricate validation rules are needed. Custom validators may increase code complexity but allow for highly tailored validation logic.

How can you use Mockito to verify that a method was called a specific number of times?

  • verifyMethod(atLeast(callCount))
  • verifyMethod(atMost(callCount))
  • verifyMethod(callCount)
  • verifyMethod(times(callCount))
In Mockito, you can use verify along with times(callCount) to verify that a method was called a specific number of times. This is useful for testing the behavior of methods.

In a Spring Boot application, how can you validate a field based on multiple conditions or constraints?

  • Using only the @NotNull annotation
  • Combining multiple annotations like @Min, @Max, and @Pattern
  • Creating a custom validator class for each condition
  • Using JavaScript to validate the field on the client-side
To validate a field based on multiple conditions or constraints in a Spring Boot application, you can combine multiple annotations like @Min, @Max, and @Pattern. These annotations allow you to define various rules for a single field. Creating a custom validator class for each condition (Option 3) would be cumbersome and is not the recommended approach.