spirng boot使用spring.profiles.active=dev运行,Bee自动选择active对应的配置文件

本文介绍了如何在JavaSpringBoot项目中使用`bee-spring-boot-starter`或`bee-spring-boot`时自动加载`spring.profiles.active`配置,以及在不使用这些框架时,如何通过BeeUseSpringbootActive类动态更新配置。重点提及了`bee-dev.properties`对`bee.properties`的覆盖机制。

运行:

java -jar bee-demo-2.1.8.jar --spring.profiles.active=dev

有两个文件:

bee.properties

bee-dev.properties


bee-dev.properties里设置的文件,将会覆盖bee.properties里的;

(另外,application-dev.properties里有的bee的配置,也将会覆盖bee-dev.properties和bee.properties的)

V2.1.8开始,
1) 使用bee-spring-boot-starter或bee-spring-boot,默认会激活active的配置;
2) 若只是使用spring boot,没有使用1)的两个框架,则需要使用编码的方式,激活.

在spring boot工程的Application类包下,
定义一个类BeeUseSpringbootActive:

// 写对应包名

/**
 * 没有使用bee-spring-boot时,根据启动的命令行参数(--spring.profiles.active)动态更新配置示例.
 * 若使用bee-spring-boot时,不需要写这个类.
 * 该类所在包,Application类要能检测到.
 * @author Kingstar
 * @since  2.1.8
 */

import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.teasoft.honey.osql.core.HoneyConfig;
import org.teasoft.honey.util.StringUtils;

@Component
public class BeeUseSpringbootActive implements EnvironmentAware {

	@Override
	public void setEnvironment(Environment environment) {
		String active = environment.getProperty("spring.profiles.active");

		if (StringUtils.isNotBlank(active))
			HoneyConfig.getHoneyConfig().overrideByActive(active);
	}

}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值