What happens when a Spring Bean is marked as @Scope(value = "prototype")?
ASingle instance per application
BNew instance every request
CShared among multiple requests
DDisposed after each request
Explanation
@Scope(value = "prototype") creates a new bean instance for every request, unlike singleton scope.
Q172
Which Spring component is primarily used for dependency injection?
AApplicationContext
BModelAndView
CInitBinder
DJdbcTemplate
Explanation
ApplicationContext is responsible for managing bean lifecycle and injecting dependencies; the others serve different purposes.
Q173
A company needs to implement fault tolerance. Which Spring feature should they use?
ASpring Boot Actuator
BSpring Retry
CSpring Webflux
DSpring AOP
Explanation
Spring Retry allows for automatic retry of operations that fail, while the others support different functionalities.
Q174
You are configuring a Spring application. What happens when you annotate a method with @Transactional?
AIt defines a new transaction.
BIt rolls back on any exception.
CIt requires database access.
DIt enforces lazy loading.
Explanation
The @Transactional annotation ensures the method's transactions will roll back on unhandled exceptions; the other options mischaracterize its behavior.
Q175
Which service in Spring allows asynchronous method execution?
A@Async
B@Controller
C@Repository
D@Value
Explanation
@Async allows methods to run asynchronously, while other annotations serve different purposes.
Q176
A company needs to handle large data in a streaming fashion. Which Spring module is best suited for this requirement?
ASpring Batch
BSpring Data JPA
CSpring WebFlux
DSpring MVC
Explanation
Spring WebFlux supports reactive programming, making it ideal for data streaming, unlike others.
Q177
What happens when you annotate a configuration class with @ComponentScan but omit base packages?
AOnly package specified is scanned.
BNo beans are detected.
CScans current package and sub-packages.
DThrows a configuration error.
Explanation
Omitting base packages defaults to scanning the package of the configuration class, unlike the others.
Q178
Which service allows for dependency injection in Spring?
ASpring IoC Container
BSpring AOP
CSpring MVC
DSpring Data
Explanation
The Spring IoC Container manages the instantiation and lifecycle of beans, enabling dependency injection. The other options serve different purposes such as aspects, web applications, or data access.
Q179
A company needs to externalize configuration properties in a Spring application. What approach should they take?
AUse application.properties file
BHard-code properties in classes
CUse environment variables exclusively
DIgnore externalization, use defaults
Explanation
The application.properties file allows for flexible configuration management while the other options lack portability or proper management.
Q180
You are configuring a Spring Boot application to use profiles. What happens when a profile is activated?
AOverrides default properties
BDisables application context
CAlways adds new beans
DStops the application from running
Explanation
Activating a profile overrides default properties, while the other options don't describe typical profile behavior.