Springboot 获取.yml中自定义参数

根据不同环境获取不同参数,放在配置文件便于更改!

 回调appId(测试用)

通过以下方式实现:

1,通过@ConfigurationProperties(prefix = "weixinAndAPP")注解,代码如下

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
 * @ClassName:  TestRY
 * @Description:TODO(配置类)
 * @author: sunfee
 * @date: 2019年12月09日
 */
@Component
@ConfigurationProperties(prefix = "weixinAndAPP")
public class TestRY {

    private String appId;

    private String hotline;

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getHotline() {
        return hotline;
    }

    public void setHotline(String hotline) {
        this.hotline = hotline;
    }
}

在方法中调用,只需要注入资源就可: 

@Autowired 

private TestRY testRY;

testRY.getAppId();                testRY.getHotline();

 

方法直接调用赋值即可。

 

 

 

 

 

 

 

posted @ 2019-12-09 17:58  sunfee  阅读(7765)  评论(1编辑  收藏  举报