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

SpringBoot中讀取application.properties配置文件的方法

 更新時(shí)間:2023年02月07日 09:50:12   作者:Knight_AL  
這篇文章主要介紹了SpringBoot中讀取application.properties配置文件的三種方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧

application.properties有以下這幾條數(shù)據(jù)

方法一:@Value注解+@Component

建議properties少的時(shí)候用,多的時(shí)候就不要使用這種方法了

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class UserController {
    @Value("${wx.open.app_id}")
    private String appid;
    @Value("${wx.open.app_secret}")
    private String secret;
    @Value("${wx.open.redirect_url}")
    private String url;
    @RequestMapping("hello")
    public String test(){
        return appid+"---"+secret+"---"+url;
    }
}

另一種方法

創(chuàng)建一個(gè)WeProperties

@Component
@Data
public class WeProperties {
    @Value("${wx.open.app_id}")
    private String appid;
    @Value("${wx.open.app_secret}")
    private String secret;
    @Value("${wx.open.redirect_url}")
    private String url;
}

Controller層

@RestController
public class UserController {
    @Autowired
    private WeProperties properties;
    @RequestMapping("hello")
    public String test(){
        return properties.getAppid()+"---"+properties.getSecret()+"---"+properties.getUrl();
    }
}

方法二:@Component+@ConfigurationProperties

創(chuàng)建一個(gè)WeProperties

后面的屬性名一定要保持一致

@Component
@ConfigurationProperties(prefix = "wx.open")
@Data
public class WeProperties {
    private String appid;
    private String app_secret;
    private String redirect_url;
}

Controller層

@RestController
public class UserController {
    @Autowired
    private WeProperties properties;
    @RequestMapping("hello")
    public String test(){
        return properties.getAppid()+"---"+properties.getApp_secret()+"---"+properties.getRedirect_url();
    }
}

方法三:@ConfigurationProperties+@EnableConfigurationProperties

創(chuàng)建一個(gè)WeProperties

后面的屬性名一定要保持一致

@ConfigurationProperties(prefix = "wx.open")
@Data
public class WeProperties {
    private String appid;
    private String app_secret;
    private String redirect_url;
}

啟動(dòng)類添加@EnableConfigurationProperties

@SpringBootApplication
@EnableConfigurationProperties(value = WeProperties.class)
public class PropertiesApplication {
    public static void main(String[] args) {
        SpringApplication.run(PropertiesApplication.class,args);
    }
}

Controller層

@RestController
public class UserController {
    @Autowired
    private WeProperties properties;
    @RequestMapping("hello")
    public String test(){
        return properties.getAppid()+"---"+properties.getApp_secret()+"---"+properties.getRedirect_url();
    }
}

到此這篇關(guān)于SpringBoot中讀取application.properties配置文件的方法的文章就介紹到這了,更多相關(guān)SpringBoot讀取application.properties內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java 將 list 字符串用逗號(hào)隔開拼接字符串的多種方法

    java 將 list 字符串用逗號(hào)隔開拼接字符串的多種方法

    這篇文章主要介紹了java 將 list 字符串用逗號(hào)隔開拼接字符串,本文給大家分享四種方法,每種方法通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-12-12
  • Java?OpenCV學(xué)習(xí)之Mat的基本操作詳解

    Java?OpenCV學(xué)習(xí)之Mat的基本操作詳解

    OpenCV用來存儲(chǔ)圖像,很多時(shí)候都會(huì)用到這個(gè)Mat方法。數(shù)字圖像可看做一個(gè)數(shù)值矩陣,?其中的每一個(gè)元素表明一個(gè)像素點(diǎn)。Mat在?OpenCV?中表示的是?N?維稠密矩陣,與稠密矩陣相對(duì)的是稀疏矩陣。本文將重點(diǎn)介紹OpenCV中Mat的一些基本操作,需要的可以參考一下
    2022-03-03
  • springboot?serviceImpl初始化注入對(duì)象實(shí)現(xiàn)方式

    springboot?serviceImpl初始化注入對(duì)象實(shí)現(xiàn)方式

    這篇文章主要介紹了springboot?serviceImpl初始化注入對(duì)象實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Java中占位符的超全使用方法分享

    Java中占位符的超全使用方法分享

    這篇文章主要為大家詳細(xì)介紹了Java中常見的一些占位符的使用方法,例如%d,%s等,文中的示例代碼簡(jiǎn)潔易懂,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)學(xué)習(xí)
    2023-05-05
  • JDK9的新特性之String壓縮和字符編碼的實(shí)現(xiàn)方法

    JDK9的新特性之String壓縮和字符編碼的實(shí)現(xiàn)方法

    這篇文章主要介紹了JDK9的新特性之String壓縮和字符編碼的實(shí)現(xiàn)方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-05-05
  • Spring Boot Swagger2使用方法過程解析

    Spring Boot Swagger2使用方法過程解析

    這篇文章主要介紹了Spring Boot Swagger2使用方法過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Mac下如何查看已安裝的jdk版本及其安裝目錄

    Mac下如何查看已安裝的jdk版本及其安裝目錄

    這篇文章主要介紹了Mac下如何查看已安裝的jdk版本及其安裝目錄問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Mybatis自定義Sql模板語法問題

    Mybatis自定義Sql模板語法問題

    這篇文章主要介紹了Mybatis自定義Sql模板語法問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • 解決問題:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources

    解決問題:Failed to execute goal org.apache.m

    這篇文章主要給大家介紹了關(guān)于解決問題:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources的相關(guān)資料,文中將解決的辦法介紹的非常詳細(xì),需要的朋友可以參考下
    2023-03-03
  • Java 垃圾回收機(jī)制詳解及實(shí)例代碼

    Java 垃圾回收機(jī)制詳解及實(shí)例代碼

    這篇文章主要介紹了 Java 垃圾回收機(jī)制詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-02-02

最新評(píng)論

榆树市| 张家口市| 湛江市| 禄丰县| 福清市| 吉水县| 龙泉市| 英山县| 唐海县| 金堂县| 孝昌县| 信宜市| 平远县| 孝感市| 正镶白旗| 惠水县| 南乐县| 安泽县| 西乡县| 宿松县| 渭南市| 湖州市| 大新县| 涟水县| 扎赉特旗| 新建县| 盐池县| 满洲里市| 衢州市| 平乐县| 乌兰县| 崇文区| 楚雄市| 和静县| 江华| 呼和浩特市| 福安市| 孝义市| 茶陵县| 南安市| 望江县|