Customizing the configuration item in spring boot is just one of the ways to implement it
Application.properties
Alipay.url = Https://openapi.alipaydev.com/gateway.doalipay.format = Jsonalipay.charset = UTF-8alipay.sign_ Type = RSA2
The first way:
Customizing an entity class for a configuration property
1@ConfigurationProperties (prefix = "Alipay")2 @Component3 Public classalipayconfiguration {4 5 PrivateString URL;//Request Address6 PrivateString format;//Request Data Format7 PrivateString CharSet;//request data encoding format8 PrivateString Sign_type;//Signature Method9 Ten PublicString GetUrl () { One returnURL; A } - - Public voidseturl (String url) { the This. url =URL; - } - - PublicString GetFormat () { + returnformat; - } + A Public voidsetformat (String format) { at This. Format =format; - } - - PublicString Getcharset () { - returnCharSet; - } in - Public voidSetcharset (String charset) { to This. CharSet =CharSet; + } - the PublicString Getsign_type () { * returnSign_type; $ }Panax Notoginseng - Public voidSetsign_type (String sign_type) { the This. Sign_type =Sign_type; + } A the}
Use
@Service Public class Implements alipayservice{ @Autowired private alipayconfiguration alipayconfig; Public void GetUrl () { System.out.println (Alipayconfig.geturl ()); }
}
Spring Boot Custom Configuration