欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot自定義Starter及使用

 更新時間:2023年07月25日 10:53:03   作者:「已注銷」  
這篇文章主要介紹了SpringBoot自定義Starter及使用,Starter是Spring Boot中的一個非常重要的概念,Starter相當于模塊,它能將模塊所需的依賴整合起來并對模塊內(nèi)的Bean根據(jù)環(huán)境進行自動配置,需要的朋友可以參考下

1 創(chuàng)建一個自定義Starter項目

image20220515160038568

CustomConfig

@Configuration
@EnableConfigurationProperties(value = CustomProperties.class) // 使配置類生效
@ConditionalOnProperty(prefix = "mmw.config", name = "enable", havingValue = "true") // 自動裝配條件
public class CustomConfig {
    @Resource
    private CustomProperties customProperties;
    @Bean
    public ConfigService defaultCustomConfig() {
        return new ConfigService(customProperties.getAge(), customProperties.getName(), customProperties.getInfo());
    }
}

CustomProperties

@ConfigurationProperties(prefix = "mmw.config")
public class CustomProperties {
    private Integer age;
    private String name;
    private String info;
    // getter/setter
}

ConfigService

public class ConfigService {
    private Integer age;
    private String name;
    private String info;
    public ConfigService(Integer age, String name, String info) {
        this.age = age;
        this.name = name;
        this.info = info;
    }
    public String showConfig() {
        return "ConfigService{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", info='" + info + '\'' +
                '}';
    }
}

META-INF/spring.factories

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.mmw.demo.config.CustomConfig

2 創(chuàng)建一個測試springBoot項目

image20220515161006770

application.yml

mmw:
    config:
        enable: true
        age: 26
        name: 'my custom starter'
        info: 'custom web info...'
server:
    port: 8081
spring:
    application:
        name: customStarterTestDemo

TestController

@RestController
public class TestController {
    @Resource
    private ConfigService configService;
    @GetMapping("/test")
    public String test() {
        return configService.showConfig();
    }
}

3 測試自動裝配

image20220515161241855

到此這篇關于SpringBoot自定義Starter及使用的文章就介紹到這了,更多相關自定義Starter內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Java多線程之并發(fā)編程的基石CAS機制詳解

    Java多線程之并發(fā)編程的基石CAS機制詳解

    這篇文章主要介紹了java并發(fā)編程之cas詳解,涉及cas使用場景和cas用作原子操作等內(nèi)容,具有一定參考價值,需要的朋友可以了解下
    2021-09-09
  • java日期相關類實例詳解

    java日期相關類實例詳解

    這篇文章主要介紹了java日期相關類實例詳解,小編覺得還是挺不錯的,這里分享給大家,供需要的朋友參考。
    2017-10-10
  • mybatis批量新增、刪除、查詢和修改方式

    mybatis批量新增、刪除、查詢和修改方式

    這篇文章主要介紹了mybatis批量新增、刪除、查詢和修改方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • Java實現(xiàn)TFIDF算法代碼分享

    Java實現(xiàn)TFIDF算法代碼分享

    這篇文章主要介紹了Java實現(xiàn)TFIDF算法代碼分享,對算法進行了簡單介紹,概念,原理,以及實現(xiàn)代碼的分享,具有一定參考價值,需要的朋友可以了解下。
    2017-11-11
  • Javaweb基礎入門requse原理與使用

    Javaweb基礎入門requse原理與使用

    Request對象的作用是與客戶端交互,收集客戶端的Form、Cookies、超鏈接,或者收集服務器端的環(huán)境變量,接下來本篇將詳細講述
    2021-11-11
  • 多模塊maven的deploy集成gitlab?ci自動發(fā)版配置

    多模塊maven的deploy集成gitlab?ci自動發(fā)版配置

    這篇文章主要為大家介紹了多模塊maven項目deploy集成gitlab?ci自動發(fā)版的配置流程步驟,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2022-02-02
  • Spring中實現(xiàn)定時調(diào)度的幾種方法

    Spring中實現(xiàn)定時調(diào)度的幾種方法

    本篇文章主要介紹了Spring中實現(xiàn)定時調(diào)度示例,可以在無人值守的時候系統(tǒng)可以在某一時刻執(zhí)行某些特定的功能,有興趣的可以了解一下。
    2017-02-02
  • maven <repositories>標簽和<pluginRepositories>標簽的使用

    maven <repositories>標簽和<pluginRepositories>標簽的使用

    這篇文章主要介紹了maven <repositories>標簽和<pluginRepositories>標簽的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-07-07
  • java 兩個數(shù)組合并的幾種方法

    java 兩個數(shù)組合并的幾種方法

    本篇文章主要介紹了java 兩個數(shù)組合并的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • 鑒權認證+aop+注解+過濾feign請求的實例

    鑒權認證+aop+注解+過濾feign請求的實例

    這篇文章主要介紹了鑒權認證+aop+注解+過濾feign請求的實例講解,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03

最新評論