最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

springboot的SpringPropertyAction事務(wù)屬性源碼解讀

 更新時(shí)間:2023年11月03日 10:47:33   作者:codecraft  
這篇文章主要介紹了springboot的SpringPropertyAction事務(wù)屬性源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

本文主要研究一下springboot的SpringPropertyAction

SpringBootJoranConfigurator

org/springframework/boot/logging/logback/SpringBootJoranConfigurator.java

class SpringBootJoranConfigurator extends JoranConfigurator {
    private LoggingInitializationContext initializationContext;
    SpringBootJoranConfigurator(LoggingInitializationContext initializationContext) {
        this.initializationContext = initializationContext;
    }
    @Override
    public void addInstanceRules(RuleStore rs) {
        super.addInstanceRules(rs);
        Environment environment = this.initializationContext.getEnvironment();
        rs.addRule(new ElementSelector("configuration/springProperty"), new SpringPropertyAction(environment));
        rs.addRule(new ElementSelector("*/springProfile"), new SpringProfileAction(environment));
        rs.addRule(new ElementSelector("*/springProfile/*"), new NOPAction());
    }
}
SpringBootJoranConfigurator繼承了JoranConfigurator,其addInstanceRules添加了configuration/springProperty的動(dòng)作為SpringPropertyAction

SpringPropertyAction

org/springframework/boot/logging/logback/SpringPropertyAction.java

class SpringPropertyAction extends Action {
    private static final String SOURCE_ATTRIBUTE = "source";
    private static final String DEFAULT_VALUE_ATTRIBUTE = "defaultValue";
    private final Environment environment;
    SpringPropertyAction(Environment environment) {
        this.environment = environment;
    }
    @Override
    public void begin(InterpretationContext context, String elementName, Attributes attributes) throws ActionException {
        String name = attributes.getValue(NAME_ATTRIBUTE);
        String source = attributes.getValue(SOURCE_ATTRIBUTE);
        Scope scope = ActionUtil.stringToScope(attributes.getValue(SCOPE_ATTRIBUTE));
        String defaultValue = attributes.getValue(DEFAULT_VALUE_ATTRIBUTE);
        if (OptionHelper.isEmpty(name) || OptionHelper.isEmpty(source)) {
            addError("The \"name\" and \"source\" attributes of <springProperty> must be set");
        }
        ActionUtil.setProperty(context, name, getValue(source, defaultValue), scope);
    }
    private String getValue(String source, String defaultValue) {
        if (this.environment == null) {
            addWarn("No Spring Environment available to resolve " + source);
            return defaultValue;
        }
        return this.environment.getProperty(source, defaultValue);
    }
    @Override
    public void end(InterpretationContext context, String name) throws ActionException {
    }
}
SpringPropertyAction繼承了Action,它的主要功能就是允許從spring的environment中讀取logback的配置;其getValue方法從environment中讀取屬性,然后通過ActionUtil.setProperty寫入到InterpretationContext中

示例

<property name="LOGS" value="./logs" />
<springProperty scope="context" name="application.name" source="spring.application.name" />
<springProfile name="production">
    <appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOGS}/${application.name}.log</file>
        <!-- configuration -->
    </appender>
</springProfile>
這里通過springProperty定義了application.name屬性,其從spring environment讀取key為spring.application.name的值作為application.name的值

小結(jié)

springboot的logback可以通過springProperty來引用spring environment中的屬性在logback的配置文件中使用,其主要是通過SpringPropertyAction來實(shí)現(xiàn)的。

以上就是springboot的SpringPropertyAction事務(wù)屬性源碼解讀的詳細(xì)內(nèi)容,更多關(guān)于springboot SpringPropertyAction的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • java使用反射給對象屬性賦值的兩種方法

    java使用反射給對象屬性賦值的兩種方法

    JAVA反射機(jī)制是在運(yùn)行狀態(tài)中,對于任意一個(gè)類,都能夠知道這個(gè)類的所有屬性和方法,下面這篇文章主要給大家介紹了關(guān)于java使用反射給對象屬性賦值的兩種方法,需要的朋友可以參考下
    2023-04-04
  • spring事務(wù)隔離級別、傳播機(jī)制以及簡單配置方式

    spring事務(wù)隔離級別、傳播機(jī)制以及簡單配置方式

    這篇文章主要介紹了spring事務(wù)隔離級別、傳播機(jī)制以及簡單配置方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • SpringBoot全局異常處理之多個(gè)處理器匹配順序(最新推薦)

    SpringBoot全局異常處理之多個(gè)處理器匹配順序(最新推薦)

    這篇文章主要介紹了SpringBoot全局異常處理之多個(gè)處理器匹配順序(最新推薦),調(diào)試源碼可見匹配順序?yàn)椋寒惓蛹壐哒邇?yōu)先,再清楚點(diǎn),子類異常處理器優(yōu)先,本文給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧
    2024-03-03
  • 深入理解HashMap各個(gè)方法的源碼

    深入理解HashMap各個(gè)方法的源碼

    這篇文章主要介紹了深入理解HashMap各個(gè)方法的源碼,HashMap初始容量不能為負(fù)數(shù),若初始容量大于最大容量,則讓它等于最大容量,負(fù)載因子必須大于0,并且傳入的initialCapacity不是HashMap的容量大小,需要的朋友可以參考下
    2023-12-12
  • 淺談一下Java多線程斷點(diǎn)復(fù)制

    淺談一下Java多線程斷點(diǎn)復(fù)制

    這篇文章主要介紹了淺談一下Java多線程斷點(diǎn)復(fù)制,當(dāng)程序執(zhí)行中斷時(shí)(出現(xiàn)錯(cuò)誤、斷電關(guān)機(jī)),仍可以從上次復(fù)制過程中重新開始(不必從頭開始復(fù)制),需要的朋友可以參考下
    2023-04-04
  • Mybatis-plus自定義SQL注入器查詢@TableLogic邏輯刪除后的數(shù)據(jù)詳解

    Mybatis-plus自定義SQL注入器查詢@TableLogic邏輯刪除后的數(shù)據(jù)詳解

    這篇文章主要給大家介紹了關(guān)于Mybatis-plus自定義SQL注入器查詢@TableLogic邏輯刪除后的數(shù)據(jù)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2023-03-03
  • Java IO流 文件的編碼實(shí)例代碼

    Java IO流 文件的編碼實(shí)例代碼

    本文通過實(shí)例代碼給大家介紹了java io流文件編碼的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧
    2017-05-05
  • Spring Security整合KeyCloak保護(hù)Rest API實(shí)現(xiàn)詳解

    Spring Security整合KeyCloak保護(hù)Rest API實(shí)現(xiàn)詳解

    這篇文章主要為大家介紹了Spring Security整合KeyCloak保護(hù)Rest API實(shí)現(xiàn)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • springmvc fastjson 反序列化時(shí)間格式化方法(推薦)

    springmvc fastjson 反序列化時(shí)間格式化方法(推薦)

    下面小編就為大家?guī)硪黄猻pringmvc fastjson 反序列化時(shí)間格式化方法(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-04-04
  • 關(guān)于二分法查找Java的實(shí)現(xiàn)及解析

    關(guān)于二分法查找Java的實(shí)現(xiàn)及解析

    這篇文章主要介紹了關(guān)于二分法查找Java的實(shí)現(xiàn)及解析,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-07-07

最新評論

柯坪县| 南京市| 松原市| 镇平县| 红原县| 宽甸| 章丘市| 华阴市| 和田市| 林口县| 昌乐县| 石阡县| 桐城市| 启东市| 如皋市| 仙居县| 襄垣县| 湾仔区| 木里| 河津市| 恩平市| 海丰县| 垦利县| 海盐县| 福建省| 陆良县| 珠海市| 武强县| 荣昌县| 巴林左旗| 高碑店市| 茂名市| 沈丘县| 岗巴县| 舞阳县| 吐鲁番市| 佛山市| 扎鲁特旗| 瓮安县| 秦皇岛市| 托克托县|