运行:
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);
}
}

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

被折叠的 条评论
为什么被折叠?



