zoukankan      html  css  js  c++  java
  • spring boot 添加自定义属性

    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())
    
        }
    
    }
  • 相关阅读:
    Nodejs服务器搭建
    CRC8校验,生成多项式:X8 + X2 + X + 1
    windows server 2019添加开机启动项
    Ubuntu20.04下SSH2安装, gulp live报错解决
    Ubuntu 20.04 开机执行自定义脚本
    STUN/TURN服务器搭建
    PostgreSQL开启远程连接
    Ubuntu 20.04 开机执行自定义脚本
    CentOS下 rpm软件包的安装与卸载
    Ubuntu18.04安装JDK1.8.0_11
  • 原文地址:https://www.cnblogs.com/H-BolinBlog/p/9098904.html
Copyright © 2011-2022 走看看