Configuring written in src / resources / application.properties in:
Modify the port number:
server.port=8081
Modify context-path:
server.servlet.context-path = /demo
Again, when access to the project directly localhost: 8081 will not find the item must be added localhsot: 8081 / Demo can access
Profiles by yml file:
New application.yml in the resources directory
server: port: 8081 servlet context-path: /demo
Yml a space between the keys and values, and an upper indented two spaces
yml custom configuration:
Custom price, num, word configuration
server: port: 8081 servlet context-path: /demo price: 1 num: 2 workd: 单价${"price"},数量${"num"}
Cited in the controller:
package com.example.demo; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; @RestController public class HelloController { @Value("${word}") private String word; @GetMapping("/hello") public String hello(){ return "word:"+word; } }
To distinguish between production and development environments:
Copy application.yml
get:
application.yml for selecting a production or development environment
Configuring application-dev.yml development environment
Configuring application-pron.yml production environment
application-dev application-pron application is copy now modify the application configuration:
Empty original configuration:
spring:
profiles:
active: pron
We should not change the code using different configurations:
mvn clean package
#进入target
java -jar -Dspring.profiles.active=pron 包名