With the reactive programming model in Spring Boot, Reactive Data Repositories allow for _____ database interaction.

  • Asynchronous
  • Blocking
  • Sequential
  • Synchronous
With the reactive programming model in Spring Boot, "Reactive Data Repositories" allow for "asynchronous" database interaction. Reactive Data Repositories, part of Spring Data's reactive support, enable non-blocking database access by providing a reactive API for interacting with databases. This allows applications to efficiently work with data streams and handle concurrent requests without blocking threads.

You are working on a Spring Boot project using Spring Data JPA, and you are tasked with implementing a feature that requires a custom query and also modifies the state of the underlying database. How would you implement this while ensuring that the changes are committed to the database?

  • Using a read-only transaction.
  • Using a read-write transaction with the @Transactional annotation on the method that modifies the data.
  • Using an in-memory database for testing purposes to avoid committing changes to the actual database during development.
  • Using two separate transactions for reading and writing, ensuring that the write transaction commits the changes.
In this scenario, you should use two separate transactions for reading and writing. The read transaction fetches the data, and the write transaction modifies the data and commits the changes to the database. This approach ensures that changes are committed while maintaining the integrity of the database. Using read-only transactions or in-memory databases for testing would not fulfill the requirement.

How does the @Qualifier annotation assist in Dependency Injection in Spring?

  • It defines a custom scope for a bean.
  • It marks a bean as a prototype, ensuring a new instance is created on each request.
  • It resolves circular dependencies in the Spring context.
  • It specifies the primary bean to be injected when multiple candidates exist.
The @Qualifier annotation in Spring is used to specify the exact bean to be injected when there are multiple candidates of the same type. This helps resolve ambiguity in cases where there are multiple beans of the same type that could be injected. By using @Qualifier with the bean's name, you can explicitly indicate which bean should be injected, ensuring that the correct one is selected. It's particularly useful when you have multiple beans of the same type and need to specify which one should be used for injection.

Which component in Spring Cloud is primarily used for service discovery?

  • Eureka
  • Feign
  • Hystrix
  • Ribbon
Eureka is the Spring Cloud component primarily used for service discovery. It allows microservices to find and communicate with each other dynamically.

How can you resolve circular dependencies between beans in Spring Boot?

  • Using @Lazy annotation to delay bean initialization.
  • Ensuring that all beans depend on each other.
  • Setting the application context to auto-detect-circular-dependencies: true.
  • Using the @DependsOn annotation to specify bean dependencies explicitly.
Circular dependencies can be resolved in Spring Boot by using the @Lazy annotation to delay the initialization of beans involved in the circular dependency. This allows Spring to break the circular reference. The other options do not effectively resolve circular dependencies and may lead to issues.

In Spring Boot, _____ is used to enable caching capability in the application.

  • @CacheConfig
  • @Cacheable
  • @EnableCaching
  • @Caching
In Spring Boot, the @EnableCaching annotation is used to enable caching capability in the application. It allows you to use caching annotations like @Cacheable and @CacheEvict to control caching behavior. The other options are related to caching but not used for enabling caching at the application level.

In Spring Security, which class is primarily responsible for holding the authenticated user’s details?

  • UserDetails
  • UserPrincipal
  • AuthenticationDetails
  • SecurityContext
In Spring Security, the class primarily responsible for holding the authenticated user's details is UserDetails. It represents user information, including username, password, authorities, and account status. SecurityContext is used to hold the security context, and the other options do not typically hold user details.

How can you specify a default value for a request parameter in a Spring Boot controller method?

  • Creating a custom annotation.
  • Default values for request parameters are not supported in Spring Boot.
  • Setting the default value in the application.properties file.
  • Using the @RequestParam annotation with the defaultValue attribute.
You can specify a default value for a request parameter in a Spring Boot controller method using the @RequestParam annotation with the defaultValue attribute. This attribute allows you to provide a default value that will be used if the parameter is not present in the request. Setting the default value in the application.properties file is not the correct approach, and creating a custom annotation is not a standard way to specify default values for request parameters.

How would you use Mockito to simulate the throwing of an exception by a method?

  • Use doThrow(Exception.class).when(mockedObject).methodCall()
  • Use expect(exception).when(mockedObject).methodCall()
  • Use mockedObject.throwException(Exception.class)
  • Use when(methodCall).thenThrow(Exception.class)
In Mockito, you can simulate the throwing of an exception by a method using doThrow(Exception.class).when(mockedObject).methodCall(). This sets up the behavior that when methodCall is invoked on mockedObject, it will throw the specified exception.

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.

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.

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.