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).
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *