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
    
}

猜你喜欢

转载自www.cnblogs.com/javage/p/9160885.html