当前位置 : 主页 > 大数据 > 区块链 >

[Sprint] Bean Scope Singleton cs Prototype

来源:互联网 收集:自由互联 发布时间:2021-06-22
We can define a class to be Singleton or Prototype. If the class was defined as Prototype, then everytime when we use new keyword, it will create a new instance. // Singleton @Service( " customerService " )@Scope(ConfigurableBeanFactory.SCO

We can define a class to be Singleton or Prototype. If the class was defined as Prototype, then everytime when we use new keyword, it will create a new instance.

 

// Singleton
@Service("customerService")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class CustomerServiceImpl implements CustomerService {}

// Prototype
@Service("customerService")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class CustomerServiceImpl implements CustomerService {}
网友评论