How can you create a shared bean that is not a singleton in Spring Boot?
- Using the @Scope annotation with prototype.
- Declaring the bean as @Singleton.
- Configuring the bean as a @RequestScoped bean.
- Creating a bean without any scope annotation.
In Spring Boot, you can create a shared bean that is not a singleton by using the @Scope annotation with prototype. This means a new instance of the bean will be created every time it is requested. The other options either create a singleton bean (Option 2) or are not valid ways to achieve a shared bean with a different scope (Options 3 and 4).
Loading...
Related Quiz
- How can you handle different HTTP methods in a single method in a Spring Boot controller?
- You have a Spring Boot application that integrates with several external services. How would you structure your tests to ensure that the interactions with external services are correctly handled, without actually interacting with the real services during the tests?
- To include additional configuration files in a Spring Boot project, the _____ property can be used.
- In a microservices architecture using Spring Boot, how would you implement a shared cache to ensure that different services have access to the same cached data, maintaining consistency?
- In Spring Boot, how do you configure the TestRestTemplate to work with a specific profile during integration testing?