Spring Boot's Properties property value configuration Application.properties with custom properties

Source: Internet
Author: User

  1. Configuring property values
    Application.properties File Direct configuration:
    Com.ieen.super.name= "MDD"

    Custom properties File configuration: src/main/resources/conf/boot.properties

    Com.ieen.boot.name= "123" com.ieen.boot.value= "456"
  2. Calling methods
    Call the Application.properties property value @Value annotation:
    @Value ("${com.ieen.super.name}") private String name;

    To invoke a custom properties property value @Value annotation:

    @PropertySource ("Classpath:conf/boot.properties") public class main{    @Value ("${com.ieen.boot.name}")    Private String Bootname;}
    Note:@PropertySource annotations are introduced into custom properties starting from 1.5
    Value is custom Config//ignoreresourcenotfound default false, file does not exist error//Encoding set encoding//name for resource object Beanname@propertysource ( Value = {"Classpath:boot.properties",        "Classpath:conf/boot.properties"}, Ignoreresourcenotfound = False, encoding = "UTF-8", name = "Boot-custom.properties")

    @ConfigurationProperties Configure the Properties Property object:

    Spring Boot 1.5 Previous configuration//@ConfigurationProperties (prefix = "com.ieen.boot", locations = "classpath:conf/ Boot.properties ") @ConfigurationProperties (prefix =" Com.ieen.boot ")
    If the custom properties is added @propertysource (value = "Classpath:conf/boot.properties", encoding = "UTF-8") @Componentpublic Class Bootpropertiesbean { private String name; private String value; Public String GetName () { return name; } public void SetName (String name) { this.name = name; } Public String GetValue () { return value; } public void SetValue (String value) { this.value = value; }}
        @Autowired    private Bootpropertiesbean bean;

Spring Boot's Properties property value configuration Application.properties with custom properties

Related Article

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.