内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

Java程序員自動(dòng)組件注入的幾種方式你會(huì)哪一種?

Java程序員自動(dòng)組件注入的幾種方式你會(huì)哪一種?

創(chuàng)新互聯(lián)公司主要從事做網(wǎng)站、網(wǎng)站設(shè)計(jì)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)湯陰,十載網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792

Java程序員自動(dòng)組件注入的幾種方式你會(huì)哪一種?
Java程序員在開發(fā)的時(shí)候,一般都會(huì)遇到組件注入這個(gè)問題,回想起當(dāng)年剛進(jìn)入Java程序員這個(gè)行業(yè)的時(shí)候也遇到過這樣的問題,那么我們今天就來討論一下組件注入會(huì)有哪幾種方式,希望能幫助大家快速攻破這個(gè)技術(shù)難點(diǎn)。

注入依賴對(duì)象可以采用手工裝配或自動(dòng)裝配,在實(shí)際應(yīng)用中建議使用手工裝配,因?yàn)樽詣?dòng)裝配會(huì)產(chǎn)生未知情況,開發(fā)人員無法預(yù)見最終的裝配結(jié)果。

問題1:@Autowired 、@Inject 、@Resource 的區(qū)別

@Autowired

[if !supportLists]· [endif]Spring標(biāo)準(zhǔn)

[if !supportLists]· [endif]按照類型注入(ByType)

[if !supportLists]· [endif]AutowiredAnnotationBeanPostProcessor對(duì)其進(jìn)行處理

[if !supportLists]· [endif]支持屬性、set方法、構(gòu)造方法注入,可以聯(lián)合@Qualifier完成ByName,聯(lián)合@Primary解決同類多 Bean沖突(不推薦,除非迫不得已)

[if !supportLists]· [endif]擁有required屬性判定空

[if !supportLists]· [endif]構(gòu)造函數(shù)只能有一個(gè),構(gòu)造方法注入@Autowire可以不帶

[if !supportLists]· [endif]@Configuration中也可以不帶@Autowire

[if !supportLists]· [endif]推薦set方法、構(gòu)造方法注入

@Resource

[if !supportLists]· [endif]JSR250標(biāo)準(zhǔn)

[if !supportLists]· [endif]按照名稱注入(ByName)

[if !supportLists]· [endif]CommonAnnotationBeanPostProcessor對(duì)其進(jìn)行處理

[if !supportLists]· [endif]不支持@Qualifier、@Primary

[if !supportLists]· [endif]不支持required屬性判定空

@Inject

[if !supportLists]· [endif]JSR330

[if !supportLists]· [endif]按照名稱注入(ByType)

[if !supportLists]· [endif]支持@Qualifier、@Primary

[if !supportLists]· [endif]不支持required屬性判定空

[if !supportLists]· [endif]需要依賴

<dependency>

    <groupId>javax.inject</groupId>

    <artifactId>javax.inject</artifactId>

    <version>1</version>

</dependency>

問題2:下面代碼有沒有問題?

@Configuration

public class WorkerConfiguration {

@Autowired

Environment environment;

public WorkerConfiguration(){

    System.out.println(environment.getProperty("os.name"));

}

@Bean

public Dept dept() {

    System.out.println("dept>>>>>>>>>>>>>>>>>>>");

    return new Dept();

}

}

當(dāng)前文章:Java程序員自動(dòng)組件注入的幾種方式你會(huì)哪一種?
當(dāng)前URL:http://www.rwnh.cn/article46/jddphg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站動(dòng)態(tài)網(wǎng)站、自適應(yīng)網(wǎng)站、靜態(tài)網(wǎng)站、營銷型網(wǎng)站建設(shè)、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
六安市| 西畴县| 都江堰市| 游戏| 芒康县| 武平县| 伊宁市| 屯昌县| 镇沅| 海城市| 鸡泽县| 拉孜县| 安新县| 淮北市| 延长县| 精河县| 郯城县| 华亭县| 贡嘎县| 根河市| 沧源| 额尔古纳市| 高雄县| 陆丰市| 遂川县| 南乐县| 绥宁县| 怀宁县| 平顺县| 裕民县| 定日县| 竹溪县| 华阴市| 涪陵区| 景谷| 大名县| 梧州市| 萝北县| 朔州市| 香格里拉县| 莱州市|