Spring Boot configuration file

Source: Internet
Author: User
Tags config port number
1. Configuration Files 1) application.properties (core configuration file)
Test.a= a_properties
test.b = b_${test.a}
2) application.yml (core configuration file)
Test:
 A.yml
b_${test.a}
c.yml
d_${test.c}
3) other.properties (normal configuration file)
Other.config= This is common config!
4) Read property values in class
@Value ("${test.a}")
private String A;
@Value ("${test.b}")
private String B;

@Value ("${test.c}")
private String C;

@Value ("${test.d}")
private String D;

private static String other;
static {
ResourceBundle Obundle = Resourcebundle.getbundle ("other");
other = Obundle.getstring ("Other.config");
}

@GetMapping ("/test") public
String Testconfig () {
return a + ";" + B + ";" + C + ";" + D + ";" + oth er;
}

Note: application.properties and application.yml are automatically loaded, the same configuration takes precedence with the value set in Application.properties , toggle Profile , 2 1) Default configuration: Application.yml

Config:
 This is the default config!

# config file switch
#spring:
# Profiles:
# Active:test
2) test environment configuration: application-test.yml
Config:
 This is Test config!
3) Production environment configuration: Application-prod.yml
Config:
 This is produce config!
3. Set Context-path and port number
#设置context-path and port numbers, default to "/" and 8080
server:
/
v 18080

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.