Spring Scope注释值

Mar*_*uez 18 java spring

Spring框架是否提供String常量来替换下面示例注释中的"prototype"字符串文字值?

@Service
@Scope("prototype")
public class CustomerService 
{
......
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

Rei*_*eus 30

您可以使用Spring的BeanDefinition中的范围常量:

  • SCOPE_SINGLETON
  • SCOPE_PROTOTYPE

例如

@Scope(BeanDefinition.SCOPE_PROTOTYPE)
Run Code Online (Sandbox Code Playgroud)