Spring Boot Learning--spring boot configuration file application

Source: Internet
Author: User

The Spring boot configuration file is available in two formats: Application.properties and APPLICATION.YML. Only one of the two profiles needs to be used.

There are some differences in the syntax of the two configuration files, as follows

1. Application.properties

Server.port = 8080--Tomcat port

Server.context-path =/webname--URL path

2. Application.yml

Server

port:8080--Tomcat port, note that there are spaces after the colon

Context-path:/webname--URL path, note that there are spaces after the colon

One, the Java class uses the configuration

1. Method One

@value ("${server.port}")private String port;

2. Method Two

@Compoent @configurationproperties (prefix= "server")  Public class serverproperties{      private  String port;       Private String context-path;             // Set/get method       }

Note: Using annotations @Compoent is to facilitate the use of @autowired in other classes to reference the class

Second, sub-environment use configuration file

Create two more Profiles application-dev.yml (test environment Profile) and APPLICATION-PROD.YML (formal environment profile)

The configuration in Application.yml is as follows:

Spring:    Profiles:        Active:dev

Note: The above configuration is to use the configuration file application-dev.yml, change to Active:prod can use the configuration file application-prod.yml

Third, Java command start using configuration

Java-jar ****.jar--spring.profiles.active=dev

Note: The above configuration is to use the configuration file application-dev.yml, change to--spring.profiles.active=prod can use the configuration file application-prod.yml

Spring Boot Learning--spring boot configuration file application

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.