Spring Boot Custom Configuration

Source: Internet
Author: User
Tags string format

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.