springboot 在配置文件寫參數注入到類中


@Configuration
//配置文件位置
@PropertySource("classpath:city.properties")
//前綴
@ConfigurationProperties(prefix = "city")
public class CityProperties {

private Map<String,Integer> map = new HashMap<>();

public Map<String, Integer> getMap() {
return map;
}

public void setMap( Map<String, Integer> map) {
this.map = map;
}
}


city.map.V0441201=350
city.map.V0350600=351
city.map.V0520100=358
city.map.V0441800=363
city.map.V0330100=373
city.map.V0430400=374
city.map.V0130600=390


另一種

  
@Value(value = "${R.host}")
public String Rhost;

@Value(value = "${R.port}")
public String Rport;

在application中寫
      
R.host=localhost
R.port=6311



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM