1、配置文件 properties
alipay.appid =
alipay.privateKey =
alipay.publicKey =
alipay.signType = RSA2
alipay.charset = UTF-8
2、配置文件类
package com.vim.common.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "alipay")
@PropertySource("classpath:zfb.properties")
public class ZfbConfig {
private String appid;
private String privateKey;
private String publicKey;
private String signType;
private String charset;
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getPrivateKey() {
return privateKey;
}
public void setPrivateKey(String privateKey) {
this.privateKey = privateKey;
}
public String getPublicKey() {
return publicKey;
}
public void setPublicKey(String publicKey) {
this.publicKey = publicKey;
}
public String getSignType() {
return signType;
}
public void setSignType(String signType) {
this.signType = signType;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
}
3、配置启动类
package com.vim;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties
public class PayApplication {
public static void main( String[] args ) {
SpringApplication.run(PayApplication.class, args);
}
}
4、使用方式
package com.vim.modules.web.controller;
import com.vim.common.properties.ZfbConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@Autowired
private ZfbConfig config;
@RequestMapping(value = "/test")
public String test(){
return config.getAppid();
}
}