真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

如何理解SPRINGBOOT讀取PROPERTIES配置文件數(shù)據(jù)過(guò)程-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關(guān)如何理解SPRINGBOOT讀取PROPERTIES配置文件數(shù)據(jù)過(guò)程,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

專業(yè)成都網(wǎng)站建設(shè)公司,做排名好的好網(wǎng)站,排在同行前面,為您帶來(lái)客戶和效益!成都創(chuàng)新互聯(lián)為您提供成都網(wǎng)站建設(shè),五站合一網(wǎng)站設(shè)計(jì)制作,服務(wù)好的網(wǎng)站設(shè)計(jì)公司,成都網(wǎng)站建設(shè)、網(wǎng)站制作負(fù)責(zé)任的成都網(wǎng)站制作公司!

一.使用@ConfigurationProperties來(lái)讀取

1、Coffer entity

@Configuration@ConfigurationProperties(prefix = "coffer")@PropertySource("classpath:config/coffer.properties")public class Coffer {  private String brand;  private Double length;  private Double width;  private Double height;          //省略了get/set方法  private String[] contains;  private ArrayList fruits;  private HashMap map;}

2、Fruit entity

@Configuration@ConfigurationProperties(prefix = "coffer.fruits")@PropertySource("classpath:config/coffer.properties")public class Fruit {  private String fruitName;  private String fruitColor;        //省略了get/set方法 }

3、coffer.properties

coffer.brand=Camelcoffer.length=100.00coffer.width=80.00coffer.height=60.00coffer.contains[0]=Raincoatcoffer.contains[1]=trouserscoffer.contains[2]=hatcoffer.contains[3]=glovecoffer.contains[4]=scarfcoffer.contains[5]=hoodcoffer.fruits[0].fruitName=apricotcoffer.fruits[0].fruitColor=yellowcoffer.fruits[1].fruitName=plumcoffer.fruits[1].fruitColor=greencoffer.fruits[2].fruitName=pineapplecoffer.fruits[2].fruitColor=yellowcoffer.fruits[3].fruitName=watermeloncoffer.fruits[3].fruitColor=greencoffer.fruits[4].fruitName=strawberrycoffer.fruits[4].fruitColor=redcoffer.map.name=xiaomaocoffer.map.age=22coffer.map.gender=female

4、springbootApplicationTest

@SpringBootTestclass SpringbootApplicationTests {  @Autowired  private ApplicationContext ioc;  @Autowired  private Coffer coffer;  @Test  public void springbootTest(){    System.out.println(coffer);  }}

5、result

Coffer{  brand='Camel',   length=100.0,   width=80.0,   height=60.0,   contains=[Raincoat, trousers, hat, glove, scarf, hood],   fruits=[       Fruit{fruitName='apricot', fruitColor='yellow'},        Fruit{fruitName='plum', fruitColor='green'},        Fruit{fruitName='pineapple', fruitColor='yellow'},        Fruit{fruitName='watermelon', fruitColor='green'},        Fruit{fruitName='strawberry', fruitColor='red'}      ],   map={age=22, gender=female, name=xiaomao}}

二、使用@Value來(lái)讀取

在springTest中無(wú)法使用@Value來(lái)讀取配置屬性,需要放到Controller中去讀取

@PropertySource("classpath:config/coffer.properties")@RestControllerpublic class SpringbootController {  @Value("${coffer.brand}")  private String brand;  @Value("${coffer.height}")  private Double height;  @RequestMapping("/test")  public String springbootTest() {    return brand+"====="+height;  }}

看完上述內(nèi)容,你們對(duì)如何理解SPRINGBOOT讀取PROPERTIES配置文件數(shù)據(jù)過(guò)程有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。


文章標(biāo)題:如何理解SPRINGBOOT讀取PROPERTIES配置文件數(shù)據(jù)過(guò)程-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)鏈接:http://weahome.cn/article/iccgo.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部