Spring Boot核心-Profile配置
【博文目录>>>】
【项目源码>>>】
【Profile配置】
Profile是Spring用来针对不同的环境对不同的配置提供支持的 ,全局 Profile 配置使用appllication-{profile} .properties( 如 application-prod.properties )。通过在 app1ication.properties 中设置 spring.profiles.active= prod 来指定活动的Profile。也可以使用JVM参数在启动时指定配置文件,如-D spring.profiles.active= prod
【代码示例】
application.properties
spring.profiles.active=dev
application-dev.properties
server.port=8888
application-prod.properties
server.port=80
debug=true
package com.example.spring.boot.profile;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Author: 王俊超
* Date: 2017-07-14 21:11
* All Rights Reserved !!!
*/
@SpringBootApplication
public class SampleApplication {
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}
}
【运行结果】
spring.profiles.active=dev
spring.profiles.active=prod