注释@Scope(BeanDefinition.SCOPE_PROTOTYPE)与注释@Scope("prototype")相比有什么优点或差异吗?
发布于 2020-02-26 04:26:59
他们做同样的事情,这意味着你可以交换他们,并没有表现出不同的行为。
注释@Scope(BeanDefinition.SCOPE_PROTOTYPE)有什么优点吗?
我可以想到的优点是,当您使用预定义的常量时,您具有避免输入和节省时间的优点,而不是声明字符串文本。
发布于 2020-02-25 21:50:41
这两个表达式都是等价物,BeanDefinition.SCOPE_PROTOTYPE是ConfigurableBeanFactory接口中的常量,在接口中使用文本“原型”。
/**
* Scope identifier for the standard prototype scope: {@value}.
* <p>Note that extended bean factories might support further scopes.
* @see #setScope
* @see ConfigurableBeanFactory#SCOPE_PROTOTYPE
*/
String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;正如建议的@santossh,主要的优点是使用常量SCOPE_PROTOTYPE而不是文本"prototype"更安全。
https://stackoverflow.com/questions/60403470
复制相似问题