国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

quarkus依賴注入之三:用注解選擇注入bean

這篇具有很好參考價(jià)值的文章主要介紹了quarkus依賴注入之三:用注解選擇注入bean。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

歡迎訪問我的GitHub

這里分類和匯總了欣宸的全部原創(chuàng)(含配套源碼):https://github.com/zq2599/blog_demos

本篇概覽

  • 本文是《quarkus依賴注入》系列的第三篇,前文咱們掌握了創(chuàng)建bean的幾種方式,本篇趁熱打鐵,學(xué)習(xí)一個(gè)與創(chuàng)建bean有關(guān)的重要知識(shí)點(diǎn):一個(gè)接口如果有多個(gè)實(shí)現(xiàn)類時(shí),bean實(shí)例應(yīng)該如何選擇其中的一個(gè)呢?可以用注解來設(shè)定bean的選擇邏輯
  • 如果您熟悉spring,此刻應(yīng)該會(huì)想到ConditionalXXX注解,下面的代碼來自spring官方,注解ConditionalOnProperty的作用是根據(jù)配置信息來控制bean是否實(shí)例化,本篇咱們要掌握的是quarkus框架下的類似控制邏輯
@Service
@ConditionalOnProperty(
  value="logging.enabled", 
  havingValue = "true", 
  matchIfMissing = true)
class LoggingService {
    // ...
}
  • 本篇主要是通過實(shí)例學(xué)習(xí)以下五個(gè)注解的用法
  1. LookupIfProperty,配置項(xiàng)的值符合要求才能使用bean
  2. LookupUnlessProperty,配置項(xiàng)的值不符合要求才能使用bean
  3. IfBuildProfile,如果是指定的profile才能使用bean
  4. UnlessBuildProfile,如果不是指定的profile才能使用bean
  5. IfBuildProperty,如果構(gòu)建屬性匹配才能使用bean

源碼下載

  • 本篇實(shí)戰(zhàn)的完整源碼可在GitHub下載到,地址和鏈接信息如下表所示(https://github.com/zq2599/blog_demos)
名稱 鏈接 備注
項(xiàng)目主頁 https://github.com/zq2599/blog_demos 該項(xiàng)目在GitHub上的主頁
git倉(cāng)庫(kù)地址(https) https://github.com/zq2599/blog_demos.git 該項(xiàng)目源碼的倉(cāng)庫(kù)地址,https協(xié)議
git倉(cāng)庫(kù)地址(ssh) git@github.com:zq2599/blog_demos.git 該項(xiàng)目源碼的倉(cāng)庫(kù)地址,ssh協(xié)議
  • 這個(gè)git項(xiàng)目中有多個(gè)文件夾,本次實(shí)戰(zhàn)的源碼在quarkus-tutorials文件夾下,如下圖紅框
    quarkus依賴注入之三:用注解選擇注入bean
  • quarkus-tutorials是個(gè)父工程,里面有多個(gè)module,本篇實(shí)戰(zhàn)的module是basic-di,如下圖紅框
    quarkus依賴注入之三:用注解選擇注入bean

LookupIfProperty,配置項(xiàng)的值符合要求才能使用bean

  • 注解LookupIfProperty的作用是檢查指定配置項(xiàng),如果存在且符合要求,才能通過代碼獲取到此bean,
  • 有個(gè)關(guān)鍵點(diǎn)請(qǐng)注意:下圖是官方定義,可見LookupIfProperty并沒有決定是否實(shí)例化beam,它決定的是能否通過代碼取到bean,這個(gè)代碼就是Instance<T>來注入,并且用Instance.get方法來獲取

quarkus依賴注入之三:用注解選擇注入bean

  • 定義一個(gè)接口TryLookupIfProperty.java
public interface TryLookupIfProperty {
    String hello();
}
  • 以及兩個(gè)實(shí)現(xiàn)類,第一個(gè)是TryLookupIfPropertyAlpha.java
public class TryLookupIfPropertyAlpha implements TryLookupIfProperty {
    @Override
    public String hello() {
        return "from " + this.getClass().getSimpleName();
    }
}
  • 第二個(gè)TryLookupIfPropertyBeta.java
public class TryLookupIfPropertyBeta implements TryLookupIfProperty {
    @Override
    public String hello() {
        return "from " + this.getClass().getSimpleName();
    }
}
  • 然后就是注解LookupIfProperty的用法了,如下所示,SelectBeanConfiguration是個(gè)配置類,里面有兩個(gè)方法用來生產(chǎn)bean,都用注解LookupIfProperty修飾,如果配置項(xiàng)service.alpha.enabled的值等于true,就會(huì)執(zhí)行tryLookupIfPropertyAlpah方法,如果配置項(xiàng)service.beta.enabled的值等于true,就會(huì)執(zhí)行tryLookupIfPropertyBeta方法
package com.bolingcavalry.config;

import com.bolingcavalry.service.TryLookupIfProperty;
import com.bolingcavalry.service.impl.TryLookupIfPropertyAlpha;
import com.bolingcavalry.service.impl.TryLookupIfPropertyBeta;
import io.quarkus.arc.lookup.LookupIfProperty;
import javax.enterprise.context.ApplicationScoped;

public class SelectBeanConfiguration {

    @LookupIfProperty(name = "service.alpha.enabled", stringValue = "true")
    @ApplicationScoped
    public TryLookupIfProperty tryLookupIfPropertyAlpha() {
        return new TryLookupIfPropertyAlpha();
    }

    @LookupIfProperty(name = "service.beta.enabled", stringValue = "true")
    @ApplicationScoped
    public TryLookupIfProperty tryLookupIfPropertyBeta() {
        return new TryLookupIfPropertyBeta();
    }
}
  • 然后來驗(yàn)證注解LookupIfProperty是否生效,下面是單元測(cè)試代碼,有兩處需要注意的地方,稍后會(huì)提到
package com.bolingcavalry;

import com.bolingcavalry.service.TryLookupIfProperty;
import com.bolingcavalry.service.impl.TryLookupIfPropertyAlpha;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;

@QuarkusTest
public class BeanInstanceSwitchTest {

    @BeforeAll
    public static void setUp() {
        System.setProperty("service.alpha.enabled", "true");
    }

    // 注意,前面的LookupIfProperty不能決定注入bean是否實(shí)力話,只能決定Instance.get是否能取到,
    //所以此處要注入的是Instance,而不是TryLookupIfProperty本身
    @Inject
    Instance<TryLookupIfProperty> service;

    @Test
    public void testTryLookupIfProperty() {
        Assertions.assertEquals("from " + tryLookupIfPropertyAlpha.class.getSimpleName(),
                                service.get().hello());
    }
}

  • 上述代碼有以下兩點(diǎn)要注意
  1. 注意TryLookupIfProperty的注入方式,對(duì)這種運(yùn)行時(shí)才能確定具體實(shí)現(xiàn)類的bean,要用Instance的方式注入,使用時(shí)要用Instance.get方法取得bean
  2. 單元測(cè)試的BeforeAll注解用于指定測(cè)試前要做的事情,這里用System.setProperty設(shè)置配置項(xiàng)service.alpha.enabled,所以,理論上SelectBeanConfiguration.tryLookupIfPropertyAlpha方法應(yīng)該會(huì)執(zhí)行,也就是說注入的TryLookupIfProperty應(yīng)該是TryLookupIfPropertyAlpha實(shí)例,所以testTryLookupIfProperty中用assertEquals斷言預(yù)測(cè):TryLookupIfProperty.hello的值來自TryLookupIfPropertyAlpha
  • 執(zhí)行單元測(cè)試,如下圖,符合預(yù)期

quarkus依賴注入之三:用注解選擇注入bean

  • 修改BeanInstanceSwitchTest.setUp,將service.alpha.enabled改成service.alpha.enabled,如此理論上SelectBeanConfiguration.tryLookupIfPropertyBeta方法應(yīng)該會(huì)執(zhí)行,實(shí)例化的應(yīng)該就是TryLookupIfPropertyBeta,那么本次單元測(cè)試就不能通過了
  • 如下圖,果然,注入的實(shí)例變成了TryLookupIfPropertyBeta,但是預(yù)期的還是之前的TryLookupIfPropertyAlpha,于是測(cè)試失敗

quarkus依賴注入之三:用注解選擇注入bean

LookupUnlessProperty,配置項(xiàng)的值不符合要求才能使用bean

  • LookupIfProperty的意思是配置項(xiàng)的值符合要求才會(huì)創(chuàng)建bean,而LookupUnlessProperty恰好相反,意思是配置項(xiàng)的值不符合要求才能使用bean

  • 為了驗(yàn)證LookupUnlessProperty的效果,修改SelectBeanConfiguration.java,只修改tryLookupIfPropertyBeta方法的注解,由從之前的LookupIfProperty改為LookupUnlessProperty,屬性也改為service.alpha.enabled,現(xiàn)在的邏輯是:如果屬性service.alpha.enabled的值是true,就執(zhí)行tryLookupIfPropertyAlpha,如果屬性service.alpha.enabled的值不是true,就執(zhí)行tryLookupIfPropertyBeta

public class SelectBeanConfiguration {

    @LookupIfProperty(name = "service.alpha.enabled", stringValue = "true")
    @ApplicationScoped
    public TryLookupIfProperty tryLookupIfPropertyAlpha() {
        return new TryLookupIfPropertyAlpha();
    }

    @LookupUnlessProperty(name = "service.alpha.enabled", stringValue = "true")
    @ApplicationScoped
    public TryLookupIfProperty tryLookupIfPropertyBeta() {
        return new TryLookupIfPropertyBeta();
    }
}
  • 打開剛才的BeanInstanceSwitchTest.java,setUp方法中將service.alpha.enabled的值設(shè)為true
@BeforeAll
public static void setUp() {
	System.setProperty("service.alpha.enabled", "true");
}
  • 運(yùn)行單元測(cè)試,如下圖,符合預(yù)期

quarkus依賴注入之三:用注解選擇注入bean

  • 現(xiàn)在把service.alpha.enabled的值設(shè)為false,單元測(cè)試不通過,提示返回值是TryLookupIfPropertyBeta,這也是符合預(yù)期的,證明LookupUnlessProperty已經(jīng)生效了

    quarkus依賴注入之三:用注解選擇注入bean

  • 此刻您可能會(huì)好奇,如果配置項(xiàng)service.alpha.enabled不存在會(huì)如何,咱們將setUp方法中的System.setProperty這段代碼刪除,這樣配置項(xiàng)service.alpha.enabled就不存在了,再次執(zhí)行單元測(cè)試,發(fā)現(xiàn)SelectBeanConfiguration類的tryLookupIfPropertyAlpha和tryLookupIfPropertyBeta兩個(gè)方法都沒有執(zhí)行,導(dǎo)致沒有TryLookupIfProperty類型的bean

quarkus依賴注入之三:用注解選擇注入bean

  • 這時(shí)候您應(yīng)該發(fā)現(xiàn)了一個(gè)問題:如果配置項(xiàng)service.alpha.enabled不存在的時(shí)候如何返回一個(gè)默認(rèn)bean,以避免找不到bean呢?

  • LookupIfProperty和LookupUnlessProperty都有名為lookupIfMissing的屬性,意思都一樣:指定配置項(xiàng)不存在的時(shí)候,就執(zhí)行注解所修飾的方法,修改SelectBeanConfiguration.java,如下圖黃框所示,增加lookupIfMissing屬性,指定值為true(沒有指定的時(shí)候,默認(rèn)值是false)

quarkus依賴注入之三:用注解選擇注入bean

  • 再次運(yùn)行單元測(cè)試,如下圖,盡管service.alpha.enabled不存在,但lookupIfMissing屬性起了作用,SelectBeanConfiguration.tryLookupIfPropertyAlpha方法還是執(zhí)行了,于是測(cè)試通過

quarkus依賴注入之三:用注解選擇注入bean

IfBuildProfile,如果是指定的profile才能使用bean

  • 應(yīng)用在運(yùn)行時(shí),其profile是固定的,IfBuildProfile檢查當(dāng)前profile是否是指定值,如果是,其修飾的bean就能被業(yè)務(wù)代碼使用
  • 對(duì)比官方對(duì)LookupIfProperty和IfBuildProfile描述的差別,LookupIfProperty決定了是否能被選擇,IfBuildProfile決定了是否在容器中
# LookupIfProperty,說的是be obtained by programmatic
Indicates that a bean should only be obtained by programmatic lookup if the property matches the provided value.
# IfBuildProfile,說的是be enabled
the bean will only be enabled if the Quarkus build time profile matches the specified annotation value.
  • 接下來寫代碼驗(yàn)證,先寫個(gè)接口
public interface TryIfBuildProfile {
    String hello();
}
  • 再寫兩個(gè)實(shí)現(xiàn)類,第一個(gè)是TryIfBuildProfileProd.java
public class TryIfBuildProfileProd implements TryIfBuildProfile {
    @Override
    public String hello() {
        return "from " + this.getClass().getSimpleName();
    }
}
  • 第二個(gè)TryIfBuildProfileDefault.java
public class TryIfBuildProfileDefault implements TryIfBuildProfile {
    @Override
    public String hello() {
        return "from " + this.getClass().getSimpleName();
    }
}
  • 再來看IfBuildProfile的用法,在剛才的SelectBeanConfiguration.java中新增兩個(gè)方法,如下所示,應(yīng)用運(yùn)行時(shí),如果profile是test,那么tryIfBuildProfileProd方法會(huì)被執(zhí)行,還要注意的是注解DefaultBean的用法,如果profile不是test,那么quarkus的bean容器中就沒有TryIfBuildProfile類型的bean了,此時(shí)DefaultBean修飾的tryIfBuildProfileDefault方法就會(huì)被執(zhí)行,導(dǎo)致TryIfBuildProfileDefault的實(shí)例注冊(cè)在quarkus容器中
@Produces
@IfBuildProfile("test")
public TryIfBuildProfile tryIfBuildProfileProd() {
	return new TryIfBuildProfileProd();
}

@Produces
@DefaultBean
public TryIfBuildProfile tryIfBuildProfileDefault() {
	return new TryIfBuildProfileDefault();
}
  • 單元測(cè)試代碼寫在剛才的BeanInstanceSwitchTest.java中,運(yùn)行單元測(cè)試是profile被設(shè)置為test,所以tryIfBuildProfile的預(yù)期是TryIfBuildProfileProd實(shí)例,注意,這里和前面LookupIfProperty不一樣的是:這里的TryIfBuildProfile直接注入就好,不需要Instance<T>來注入

    @Inject
    TryIfBuildProfile tryIfBuildProfile;
    
    @Test
    public void testTryLookupIfProperty() {
    	Assertions.assertEquals("from " + TryLookupIfPropertyAlpha.class.getSimpleName(),
                                service.get().hello());
    }
    
    @Test
    public void tryIfBuildProfile() {
    	Assertions.assertEquals("from " + TryIfBuildProfileProd.class.getSimpleName(),
                    tryIfBuildProfile.hello());
    }
    
  • 執(zhí)行單元測(cè)試,如下圖,測(cè)試通過,紅框顯示當(dāng)前profile確實(shí)是test

quarkus依賴注入之三:用注解選擇注入bean

  • 再來試試DefaultBean的是否正常,修改SelectBeanConfiguration.java的代碼,如下圖紅框,將IfBuildProfile注解的值從剛才的test改為prod,如此一來,再執(zhí)行單元測(cè)試時(shí)tryIfBuildProfileProd方法就不會(huì)被執(zhí)行了,此時(shí)看tryIfBuildProfileDefault方法能否執(zhí)行

quarkus依賴注入之三:用注解選擇注入bean

  • 執(zhí)行單元測(cè)試,結(jié)果如下圖,黃框中的內(nèi)容證明是tryIfBuildProfileDefault方法被執(zhí)行,也就是說DefaultBean正常工作

quarkus依賴注入之三:用注解選擇注入bean

UnlessBuildProfile,如果不是指定的profile才能使用bean

  • UnlessBuildProfile的邏輯與IfBuildProfile相反:如果不是指定的profile才能使用bean
  • 回顧剛才測(cè)試失敗的代碼,如下圖紅框,單元測(cè)試的profile是test,下面要求profile必須等于prod,因此測(cè)試失敗,現(xiàn)在咱們將紅框中的IfBuildProfile改為UnlessBuildProfile,意思是profile不等于prod的時(shí)候bean可以使用

quarkus依賴注入之三:用注解選擇注入bean

  • 執(zhí)行單元測(cè)試,如下圖,這一次順利通過,證明UnlessBuildProfile的作用符合預(yù)期

quarkus依賴注入之三:用注解選擇注入bean

IfBuildProperty,如果構(gòu)建屬性匹配才能使用bean

  • 最后要提到注解是IfBuildProperty是,此注解與LookupIfProperty類似,下面是兩個(gè)注解的官方描述對(duì)比,可見IfBuildProperty作用的熟悉主要是構(gòu)建屬性(前面的文章中提到過構(gòu)建屬性,它們的特點(diǎn)是運(yùn)行期間只讀,值固定不變)
# LookupIfProperty的描述,如果屬性匹配,則此bean可以被獲取使用
Indicates that a bean should only be obtained by programmatic lookup if the property matches the provided value.
# IfBuildProperty的描述,如果構(gòu)建屬性匹配,則此bean是enabled
the bean will only be enabled if the Quarkus build time property matches the provided value
  • 限于篇幅,就不寫代碼驗(yàn)證了,來看看官方demo,用法上與LookupIfProperty類似,可以用DefaultBean來兜底,適配匹配失敗的場(chǎng)景
@Dependent
public class TracerConfiguration {

    @Produces
    @IfBuildProperty(name = "some.tracer.enabled", stringValue = "true")
    public Tracer realTracer(Reporter reporter, Configuration configuration) {
        return new RealTracer(reporter, configuration);
    }

    @Produces
    @DefaultBean
    public Tracer noopTracer() {
        return new NoopTracer();
    }
}
  • 至此,基于多種注解來選擇bean實(shí)現(xiàn)的學(xué)習(xí)已經(jīng)完成,依靠配置項(xiàng)和profile,已經(jīng)可以覆蓋多數(shù)場(chǎng)景下bean的確認(rèn),如果這些不能滿足您的業(yè)務(wù)需求,接下來的文章咱們繼續(xù)了解更多靈活的選擇bean的方式

歡迎關(guān)注博客園:程序員欣宸

學(xué)習(xí)路上,你不孤單,欣宸原創(chuàng)一路相伴...文章來源地址http://www.zghlxwxcb.cn/news/detail-620044.html

到了這里,關(guān)于quarkus依賴注入之三:用注解選擇注入bean的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • quarkus依賴注入之八:裝飾器(Decorator)

    quarkus依賴注入之八:裝飾器(Decorator)

    這里分類和匯總了欣宸的全部原創(chuàng)(含配套源碼):https://github.com/zq2599/blog_demos 本篇是《quarkus依賴注入》系列的第八篇,目標(biāo)是掌握quarkus實(shí)現(xiàn)的一個(gè)CDI特性:裝飾器(Decorator) 提到裝飾器,熟悉設(shè)計(jì)模式的讀者應(yīng)該會(huì)想到裝飾器模式,個(gè)人覺得下面這幅圖很好的解釋了裝飾器

    2024年02月14日
    瀏覽(45)
  • quarkus依賴注入之九:bean讀寫鎖

    quarkus依賴注入之九:bean讀寫鎖

    這里分類和匯總了欣宸的全部原創(chuàng)(含配套源碼):https://github.com/zq2599/blog_demos 本篇是《quarkus依賴注入》的第九篇,目標(biāo)是在輕松的氣氛中學(xué)習(xí)一個(gè)小技能:bean鎖 quarkus的bean鎖本身很簡(jiǎn)單:用兩個(gè)注解修飾bean和方法即可,但涉及到多線程同步問題,欣宸愿意花更多篇幅與各位

    2024年02月14日
    瀏覽(25)
  • quarkus依賴注入之五:攔截器(Interceptor)

    quarkus依賴注入之五:攔截器(Interceptor)

    這里分類和匯總了欣宸的全部原創(chuàng)(含配套源碼):https://github.com/zq2599/blog_demos 本文是《quarkus依賴注入》系列的第五篇,經(jīng)過前面的學(xué)習(xí),咱們熟悉了依賴注入的基本特性,接下來進(jìn)一步了解相關(guān)的高級(jí)特性,先從本篇的攔截器開始 如果您熟悉spring的話,對(duì)攔截器應(yīng)該不會(huì)陌

    2024年02月14日
    瀏覽(45)
  • quarkus依賴注入之二:bean的作用域

    quarkus依賴注入之二:bean的作用域

    這里分類和匯總了欣宸的全部原創(chuàng)(含配套源碼):https://github.com/zq2599/blog_demos 官方資料:https://lordofthejars.github.io/quarkus-cheat-sheet/#_injection 作為《quarkus依賴注入》系列的第二篇,繼續(xù)學(xué)習(xí)一個(gè)重要的知識(shí)點(diǎn):bean的作用域(scope),每個(gè)bean的作用域是唯一的,不同類型的作用域

    2024年02月15日
    瀏覽(16)
  • quarkus依賴注入之十二:禁用類級(jí)別攔截器

    quarkus依賴注入之十二:禁用類級(jí)別攔截器

    這里分類和匯總了欣宸的全部原創(chuàng)(含配套源碼):https://github.com/zq2599/blog_demos 本篇是《quarkus依賴注入》系列的第十二篇,繼續(xù)學(xué)習(xí)攔截器的另一個(gè)高級(jí)特性:禁用類級(jí)別攔截器 本篇由以下內(nèi)容構(gòu)成 編碼驗(yàn)證類攔截器和方法攔截器的疊加效果 用注解 NoClassInterceptors 使類攔截器

    2024年02月13日
    瀏覽(53)
  • quarkus依賴注入之十:學(xué)習(xí)和改變bean懶加載規(guī)則

    quarkus依賴注入之十:學(xué)習(xí)和改變bean懶加載規(guī)則

    這里分類和匯總了欣宸的全部原創(chuàng)(含配套源碼):https://github.com/zq2599/blog_demos 本篇是《quarkus依賴注入》系列的第十篇,來看一個(gè)容易被忽略的知識(shí)點(diǎn):bean的懶加載,咱們先去了解quarkus框架下的懶加載規(guī)則,然后更重要的是掌握如何改變規(guī)則,以達(dá)到提前實(shí)例化的目標(biāo) 總的來

    2024年02月14日
    瀏覽(25)
  • quarkus依賴注入之十三:其他重要知識(shí)點(diǎn)大串講(終篇)

    quarkus依賴注入之十三:其他重要知識(shí)點(diǎn)大串講(終篇)

    這里分類和匯總了欣宸的全部原創(chuàng)(含配套源碼):https://github.com/zq2599/blog_demos 本篇是《quarkus依賴注入》系列的終篇,前面十二篇已覆蓋quarkus依賴注入的大部分核心內(nèi)容,但依然漏掉了一些知識(shí)點(diǎn),今天就將剩下的內(nèi)容匯總,來個(gè)一鍋端,輕松愉快的結(jié)束這個(gè)系列 總的來說,

    2024年02月13日
    瀏覽(25)
  • quarkus依賴注入之十一:攔截器高級(jí)特性上篇(屬性設(shè)置和重復(fù)使用)

    quarkus依賴注入之十一:攔截器高級(jí)特性上篇(屬性設(shè)置和重復(fù)使用)

    這里分類和匯總了欣宸的全部原創(chuàng)(含配套源碼):https://github.com/zq2599/blog_demos 本篇是《quarkus依賴注入》系列的第十一篇,之前的[《攔截器》]學(xué)習(xí)了攔截器的基礎(chǔ)知識(shí),現(xiàn)在咱們要更加深入的了解攔截器,掌握兩種高級(jí)用法:攔截器屬性和重復(fù)使用攔截器 先來回顧攔截器的基

    2024年02月13日
    瀏覽(49)
  • Spring 02 -Spring依賴注入+Spring注解開發(fā)

    依賴注入:在Spring創(chuàng)建對(duì)象的同時(shí),為其屬性賦值,稱之為依賴注入。 創(chuàng)建對(duì)象時(shí),Spring工廠會(huì)通過Set方法為對(duì)象的屬性賦值。 范例:定義一個(gè)Bean類型 屬性注入 范例:定義一個(gè)Bean類型 提供構(gòu)造方法 構(gòu)造方法注入 復(fù)雜類型指的是:list、set、map、array、properties等類型 定義

    2023年04月09日
    瀏覽(27)
  • 【Spring】javaBean、依賴注入、面向切面AOP、使用注解開發(fā)

    【Spring】javaBean、依賴注入、面向切面AOP、使用注解開發(fā)

    有一定規(guī)范的Java實(shí)體類,類內(nèi)提供了一些公共方法以便外界對(duì)該對(duì)象的內(nèi)部屬性進(jìn)行操作 所有屬性都是private,所有的屬性都可以通過get/set方法進(jìn)行訪問,同時(shí)還需要有一個(gè)無參構(gòu)造(默認(rèn)就有) 高內(nèi)聚,低耦合是現(xiàn)代軟件的開發(fā)的設(shè)計(jì)模式 之前編寫的圖書管理系統(tǒng)具有高

    2024年02月08日
    瀏覽(57)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包