spring-boot的spring.profiles.active配置试验

  1. application.yml 和 application.properties 两个文件的优先级:如果你的项目中存在 application.properties 文件,那么 application.yml 文件就只是一个摆设。其实 application.yml 文件会被优先加载,而如果同时存在 application.properties 文件,并且存在相同的配置,那么则会用 application.properties 文件中的配置覆盖之前的配置;也就是说哪个文件被最后加载,哪个才具有最高级别,因为最后的,会覆盖前面所有的。

使用mian方法启动,最终生效的是application.properties文件的prod和8032端口

spring-boot的spring.profiles.active配置试验

 

假如启动时指定参数,则优先级是最高的

java -jar 名称.jar --spring.profiles.active=test

spring-boot的spring.profiles.active配置试验

spring-boot的spring.profiles.active配置试验

 

  1. 加载自定义配置文件,使用注解

import org.springframework.context.annotation.Configuration;

import org.springframework.context.annotation.PropertySource;

spring-boot的spring.profiles.active配置试验

spring-boot的spring.profiles.active配置试验spring-boot的spring.profiles.active配置试验

  1. 待续