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 {
// ...
}
- Spring API Docs.
- Example of the mapping.
- Scope annotation reference.
As of the current spring version 4.3.2
, we can use @Scope("prototype") annotation.
@Scope("prototype")
@Repository
public class MovieFinderImpl implements MovieFinder {
// ...
}