簡體   English   中英

@Scope (BeanDefinition.SCOPE_PROTOTYPE) 和 @Scope (“prototype”) 有什么區別?

[英]What is the difference between @Scope (BeanDefinition.SCOPE_PROTOTYPE) and @Scope (“prototype”)?

與注解@Scope("prototype")相比,注解@Scope(BeanDefinition.SCOPE_PROTOTYPE)有什么優點或區別嗎?

它們做同樣的事情,這意味着您可以互換它們並且在行為上沒有區別。

注解@Scope(BeanDefinition.SCOPE_PROTOTYPE) 有什么好處嗎?

我能想到的優點是當您使用預定義的常量時,您可以避免拼寫錯誤並節省時間,而不是聲明字符串文字。

兩個表達式都當量, BeanDefinition.SCOPE_PROTOTYPE是在一個恆定ConfigurableBeanFactory與文本界面“原型”是在所使用的BeanDefinition接口

/**
 * 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-kumhar 所建議的,主要優點是使用常量SCOPE_PROTOTYPE而不是文本"prototype"更安全。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM