Spring Boot Basics: Configuration file configuration variables

Source: Internet
Author: User

First, the configuration

Resources under Application.properties

1. General Configuration

Resources under Application.properties, such as write: server.port=9090, then the boot port is 9090

2. Custom Configuration

3. Reference to configuration variables

4, Random value configuration: If the parameters are random, you can be in the configuration file with

5, Random port configuration: To avoid port conflict problems

  #server. Port=9090  server.port  =${random. int  [1024 , 9999 ]}//  random port  gwf.num=${random. int }//  random number  Gwf.hello=hello//  Gwf.name = GWF ${gwf.hello} ${gwf.num}//  reference to configuration variable   
@RestController  Public class Hellocontroller {    @Value ("${gwf.name}")    private  String msg;    @RequestMapping ("/hello")    public  String Hello () {        returnthis. msg;    }}

Use is referred to by the annotation @Value ("${}"), which is somewhat analogous to the way in which a JSP variable is evaluated

Second, yml configuration file

Yaml is a language for writing configuration files, it is a natural tree structure

Third, log configuration file

Logback.xml, can Baidu query

Four, multi-environment configuration

Application-{profile}.properties,profile represents an environment variable

After packaging, go to the jar store directory and execute the command:

Java-jar ***.jar--spring.profilr.active=dev/test, performing the development environment and test environment respectively

Spring Boot Basics: Configuration file configuration variables

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.