中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

網(wǎng)站建設(shè)與開發(fā)的收獲與體會信息流優(yōu)化

網(wǎng)站建設(shè)與開發(fā)的收獲與體會,信息流優(yōu)化,自己做企業(yè)網(wǎng)站可以嗎,百度域名對應(yīng)的ip地址文章目錄1. Autowired和Resource的區(qū)別2. 一個接口多個實現(xiàn)類的處理2.1 注入時候報錯情況2.2 使用Primary注解處理2.3 使用Qualifer注解處理2.4 根據(jù)業(yè)務(wù)情況動態(tài)的決定注入哪個serviceImpl1. Autowired和Resource的區(qū)別 Aurowired是根據(jù)type來匹配;Resource可以根…

文章目錄

  • 1. @Autowired和@Resource的區(qū)別
  • 2. 一個接口多個實現(xiàn)類的處理
    • 2.1 注入時候報錯情況
    • 2.2 使用@Primary注解處理
    • 2.3 使用@Qualifer注解處理
    • 2.4 根據(jù)業(yè)務(wù)情況動態(tài)的決定注入哪個serviceImpl

1. @Autowired和@Resource的區(qū)別

  1. @Aurowired是根據(jù)type來匹配;@Resource可以根據(jù)name和type來匹配,默認是name匹配
  2. @Aurowired是Spring定義的注解,@Resource是JSR250規(guī)范里面定義的注解,而Spring對JSR250規(guī)范提供了支持。
  3. @Autowired如果需要支持name匹配,就需要配合@Primary或者@Qualifier注解使用來實現(xiàn)

2. 一個接口多個實現(xiàn)類的處理

public interface FileService {void getFile();
}
@Slf4j
@Service
public class FileServiceAImpl implements FileService {@Overridepublic void getFile() {log.info("調(diào)用fileServiceAImpl...");}
}
@Slf4j
@Service
public class FileServiceBImpl implements FileService {@Overridepublic void getFile() {log.info("調(diào)用fileServiceBImpl...");}
}

2.1 注入時候報錯情況

在這里插入圖片描述

2.2 使用@Primary注解處理

@Primary表示主要的bean,當存在多個相同類型的Bean的時候,優(yōu)先使用聲明了@Primary的Bean

FileServiceAImpl 類添加@Primary注解:

@Slf4j
@Service
@Primary
public class FileServiceAImpl implements FileService {@Overridepublic void getFile() {log.info("調(diào)用fileServiceAImpl...");}
}

在這里插入圖片描述

2.3 使用@Qualifer注解處理

@Qualifer的作用類似于條件篩選,它可以根據(jù)Bean的名字找到需要裝備的目標Bean

@Slf4j
@Service("fileServiceAImpl")
public class FileServiceAImpl implements FileService {@Overridepublic void getFile() {log.info("調(diào)用fileServiceAImpl...");}
}
@Slf4j
@Service("fileServiceBImpl")
public class FileServiceBImpl implements FileService {@Overridepublic void getFile() {log.info("調(diào)用fileServiceBImpl...");}
}
@Slf4j
@SpringBootTest
class FileServiceTest {@Autowired@Qualifier("fileServiceBImpl")private FileService fileService;@Testvoid getFile() {fileService.getFile();}}

在這里插入圖片描述

2.4 根據(jù)業(yè)務(wù)情況動態(tài)的決定注入哪個serviceImpl

使用 ApplicationContext的getBean()方法動態(tài)指定需要用到的bean

@Slf4j
@SpringBootTest
class FileServiceTest {@Autowiredprivate ApplicationContext context;@Testvoid getFile() {FileService fileService = getFileService(0);fileService.getFile();}/*** 根據(jù)業(yè)務(wù)參數(shù)生成需要的bean* @param num 具體的業(yè)務(wù)參數(shù)* @return*/private FileService getFileService(int num){FileService fileService;if(num==1){fileService = context.getBean("fileServiceBImpl",FileService.class);}else {fileService = context.getBean("fileServiceAImpl",FileService.class);}return fileService;}
}

在這里插入圖片描述

http://www.risenshineclean.com/news/60861.html

相關(guān)文章:

  • 搜索李曉峰女生做sem還是seo
  • 簡約大氣網(wǎng)站設(shè)計欣賞愛站seo綜合查詢
  • 企業(yè)門戶網(wǎng)站布局特征軟件推廣平臺
  • 手機企業(yè)網(wǎng)站推廣網(wǎng)絡(luò)廣告的計費方式
  • 宜昌網(wǎng)頁設(shè)計便宜的seo網(wǎng)絡(luò)營銷推廣
  • 電子政務(wù)政府網(wǎng)站建設(shè)方案云客網(wǎng)平臺
  • 沒簽合同網(wǎng)站做不好百度極簡網(wǎng)址
  • 購物網(wǎng)站平臺建設(shè)自己做網(wǎng)站
  • 自己怎么建立自己的國際網(wǎng)站晉城今日頭條新聞
  • 網(wǎng)站域名com和cn百度識圖網(wǎng)頁版
  • 帝國cms做中英文網(wǎng)站電商網(wǎng)站建設(shè)哪家好
  • 地方門戶網(wǎng)站建設(shè)要求福州百度分公司
  • wordpress附件插件南寧seo推廣優(yōu)化
  • 建設(shè)企業(yè)資質(zhì)雙網(wǎng)是哪兩個網(wǎng)站線上推廣平臺都有哪些
  • 福州正規(guī)網(wǎng)站建設(shè)公司報價軟文廣告案例分析
  • 酒店網(wǎng)站設(shè)計模板免費創(chuàng)建網(wǎng)站的平臺
  • 手機微網(wǎng)站優(yōu)化大師使用心得
  • 網(wǎng)站建設(shè)聯(lián)盟深圳互聯(lián)網(wǎng)公司50強
  • 自適應(yīng)網(wǎng)站如何做mip網(wǎng)頁快速排名優(yōu)化seo
  • 長葛網(wǎng)站建設(shè)公司最近國際新聞大事20條
  • 定制開發(fā)平臺電商網(wǎng)站seo怎么做
  • 哪個網(wǎng)站可以接任務(wù)做兼職移動網(wǎng)站如何優(yōu)化排名
  • 網(wǎng)站開發(fā)期間賬務(wù)處理新產(chǎn)品推廣
  • 網(wǎng)站設(shè)計步驟畢業(yè)論文互聯(lián)網(wǎng)營銷師證書怎么考多少錢
  • 湛江cms建站排名點擊工具
  • 千華網(wǎng)鞍山門戶網(wǎng)站關(guān)鍵詞搜索站長工具
  • h5制作軟件電腦百度ocpc怎么優(yōu)化
  • 中國建設(shè)銀行北海招聘信息網(wǎng)站百度旗下產(chǎn)品
  • 視頻網(wǎng)站app怎么做的長春做網(wǎng)絡(luò)優(yōu)化的公司
  • 外貿(mào)網(wǎng)站推廣計劃關(guān)鍵詞排名工具