赞
踩
有两种情况,
这种情况直接使用 ==@Value("${xx.yy}")==来获取
import org.springframework.beans.factory.annotation.Value;
@Value("${wx.appId}")
public String AppId;
这个配置类的文件就是读取数据后,会在其他类中去使用这些数据。
这种方式和之前相比就需要在config类前面增加一个注解==@Component==不加这个注解读取不出来。。
package com.loneyfeather.testwxloginfo.util; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class WxConfig { @Value("${wx.appId}") public String AppId; @Value("${wx.appSecret}") public String AppSecret; public String getAppId() { return AppId; } public String getAppSecret() { return AppSecret; } }
下面是配置文件的内容,因为涉及到数据所以会有缺失
这是 application-xxx.yml文件
#微信相关配置
wx:
#appId (到时候换成自己公众号的)
appId: xxxxxxxxxx
#appSecret(到时候换成自己公众号的)
appSecret: xxxxxxxxxxxxxx
以上就是我读取配置文件的方法。当然还有很多种方法。
因为目前我没有去研究所以就先空在那。。
------------------------------------------------------孤翼晓晓==============
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。