How spring boot reads the configuration file

Source: Internet
Author: User

Spring boot further encapsulates the original configuration of spring, making the program apes a lot easier, really thanks to the spring boot

In everyday code, the read profile properties are often encountered in the business logic of their own writing, and spring boot provides two ways (I know)

1)@Value

@Value ("${profile property name}")

For example

@Value ("${agr-farmer.url}")//The Agr-farmer.url property value is placed in the URL.     Private  String Url;

Configuration file

Agr-farmer.url= 127.0.0.1:8009/app

What if more than one attribute should be done?

Using Annotations @ConfigurationProperties

@Component @configurationproperties (prefix= "Agr-farmer-config")  Public class Agrfarmer {    ///  virtuals Key-value pair    privatenew hashmap<> ();    // Normal value     Private   String key;     // omit Get,set Method }    

The configuration file format is YML

agr-farmer-config:  virtuals:    key1:value1#key:value    key2:value2#key:value  key:t1kmknylx #单值 

How spring boot reads the configuration file

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.