spring boot中读取配置文件的两种方式

application.properties

test.name=测试
test.url=www.test.com

1.@Value注解

在controller里可以这样直接调用

@Value("${test.name}")
private String name;

@Value("${test.url}")
private String url;

2.@ConfigurationProperties(prefix="test")

新建一个ConfigTest.java

@Component  
@ConfigurationProperties(prefix="test")
public class ConfigTest(){

    private String name;

    private String url;

  //get--set
    
}

 

posted on 2018-06-09 21:23  Java挖掘机  阅读(173)  评论(0编辑  收藏  举报

导航