日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
springboot中的properties參數(shù)配置詳解

application.properties

創(chuàng)新互聯(lián)是一家專業(yè)提供方城企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計、H5高端網(wǎng)站建設(shè)、小程序制作等業(yè)務(wù)。10年已為方城眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。

application.properties是spring boot默認(rèn)的配置文件,spring boot默認(rèn)會在以下兩個路徑搜索并加載這個文件

src\main\resources
src\main\resources\config

配置系統(tǒng)參數(shù)

在application.properties中可配置一些系統(tǒng)參數(shù),spring boot會自動加載這個參數(shù)到相應(yīng)的功能,如下

#端口,默認(rèn)為8080 
server.port=80 
#訪問路徑,默認(rèn)為/ 
server.context-path=/test 
#輸出日志文件,默認(rèn)不輸出  
logging.file=/log.txt 
#修改日志級別,默認(rèn)為INFO 
logging.level.root=DEBUG 

自定義properties文件

在spring boot啟動類或配置類中添加以下注解,可在啟動時載入自定義的配置文件

@PropertySource("classpath:config/xxx.properties") 

如果要同時載入多個文件

@PropertySource(value={"classpath:config/a.properties","classpath:config/b.properties"}) 

自定義參數(shù)

以自命名配置一些參數(shù),如

key1=values1 
key2=values2 

在JAVA代碼中,使用@Value注解,在項目啟動時會將自定義參數(shù)加載到全局變量,如下

@RestController 
public class SampleController { 
  @Value(value="${key1}") 
  private String key; 

批量注入到類變量

在properties中配置兩個以a為前綴的參數(shù)

a.key1=values1 
a.key2=values2 

在JAVA中用@ConfigurationProperties 將以a為前綴的參數(shù)注入到當(dāng)前變量中,需要有setXxx()方法

@RestController 
@ConfigurationProperties(prefix = "a") 
public class SampleController { 
  private String key1; 
  private String key2; 
  public void setKey1(String key1) { 
    this.key1 = key1; 
  } 
  public void setKey2(String key2) { 
    this.key2 = key2; 
  } 

總結(jié)

以上所述是小編給大家介紹的spring boot中的properties參數(shù)配置詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對創(chuàng)新互聯(lián)網(wǎng)站的支持!


名稱欄目:springboot中的properties參數(shù)配置詳解
文章起源:http://www.dlmjj.cn/article/jhhgcg.html