1.添加jar
compile('org.springframework.boot:spring-boot-configuration-processor:1.2.0.RELEASE')
2.在application.properties中设置自定义属性
#------微信App支付参数------ #终端设备号(门店号或收银设备ID),默认请传"WEB" weixinpay.device_info=WEB #符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型 weixinpay.fee_type=CNY #微信开放平台审核通过的应用APPID weixinpay.appid=******* #微信支付分配的商户号 weixinpay.mch_id=******** #接收微信支付异步通知回调地址,通知url必须为直接可访问的url,不能携带参数。 weixinpay.notify_url=***********
3.自定义对象
import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.stereotype.Component @ConfigurationProperties(prefix = "weixinpay") @Component class WeiXinPayConfig { var device_info: String? = null var fee_type: String? = null var appid: String? = null var mch_id: String? = null var notify_url: String? = null override fun toString(): String { return "WeiXinPayConfig(device_info=$device_info, fee_type=$fee_type, appid=$appid, mch_id=$mch_id, notify_url=$notify_url)" } }
4.可直接使用
import com.lanhetech.paymodule.config.WeiXinPayConfig import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RestController @RestController class PayModuleController { val logger = LoggerFactory.getLogger(this.javaClass) @Autowired var weiXinPayConfig: WeiXinPayConfig? = null @GetMapping("/payByWeiXin") fun payByWeiXin() { logger.info(weiXinPayConfig.toString()) } }