[Java Spring] Profiles

Profiles allow us to do different configurations based on different env.

application.yml:

spring:
  profiles: dev
server:
  port: 8000
---
spring:
  profiles: test
server:
  port: 9000

We set 'dev' env to run on port 8000, but test env is on port 9000.

 

Build:

mvn clean package

 

Then run:

java -jar -Dspring.profiles.active=dev target/xxxx.jar

You will see that port is 8000.

 

If you run:

java -jar -Dspring.profiles.active=test target/xxxx.jar

Then it will be 9000.

 

Real world usecases:

1. Third-party dependencies

2. LogLevel cahgnes

3. Service deployments

4. Internal resource deployments

上一篇:SpringBoot之JAVA代码获取yml配置(注解)


下一篇:小程序配置请求地址