作用域:
singleton:单列模式
prototype:原型模式
注:spring默认为单列模式
例子1:@Score("singleton")
import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; /* 设置Bean在spring容器中以单列模式存在 */ @Scope("singleton") @Component public class SingleScopeTest { }
例子2:@Scope("prototype")
1 import org.springframework.context.annotation.Scope; 2 import org.springframework.stereotype.Component; 3 /* 4 设置Bean在spring容器中以多例形式存在 5 */ 6 @Scope("prototype") 7 @Component 8 public class PrototypeScoreTest { 9 }