美文网首页
springboot 读取properties

springboot 读取properties

作者: 白敏鸢 | 来源:发表于2018-05-21 16:11 被阅读0次

配置文件

server.properties
linking.bpmaddress={BMP_ADDRESS}

修改环境变量

name:BMP_ADDRESS 
value:http://111.111.111.111

添加工具配置类

@Configuration
@ConfigurationProperties(prefix="linking")
@PropertySource("file:{user.dir}/conf/server.properties")
public class ServerConfig implements ServerConfigService,InitializingBean
{
private String bpmaddress;
get/set;
}

业务类使用

public class WebServiceImpl  implements WebService 
{
    @Autowried
    ServerConfig  serverConfig;

    @Override
    public String query()
    {
    String url =serverConfig.getserverConfig();
       .......
    return null;
    }

}

注意问题

@ConfigurationProperties(prefix="linking")
只去读取前缀为linking的配置文件

相关文章

网友评论

      本文标题:springboot 读取properties

      本文链接:https://www.haomeiwen.com/subject/grxqjftx.html