application.properties 的属性值可以直接通过注解获取
apiService.url=http://192.168.50.158:2911
@Value("${apiService.url}") private String apiServiceUrl;
application.yml 的属性值则麻烦一些,通过创建一个Bean来接收
apiService: url: http://192.168.50.158:2225
package com.dakun.jianzhong.config; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @Component @ConfigurationProperties(prefix="apiService") public class ApiServiceProperties { String url ; public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } }