Create prototype scoped Spring bean with annotations? Create prototype scoped Spring bean with annotations? spring spring

Create prototype scoped Spring bean with annotations?


You can use the @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) annotation.

@Service@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)public class CustomerService {    // ...}
  1. Spring API Docs.
  2. Example of the mapping.
  3. Scope annotation reference.


As of the current spring version 4.3.2, we can use @Scope("prototype") annotation.

@Scope("prototype")@Repositorypublic class MovieFinderImpl implements MovieFinder {    // ...}


In Spring 5, You can use as follows

@Component("myBean")

@Scope("prototype")

public class MyBeanClass{//your logics}