gpt4 book ai didi

java - 我可以在 Spring Boot 配置文件中定义系统属性吗?

转载 作者:IT老高 更新时间:2023-10-28 20:42:05 25 4
gpt4 key购买 nike

我的 Spring Boot 应用程序有一个 application.yml 配置文件,它定义了两个配置文件(如 documentation 中所述)。

启用生产配置文件后,我想设置 http.maxConnections系统属性为自定义值,例如

spring:
profiles:
active: dev
---
spring:
profiles: dev
---
spring:
profiles: production
http:
maxConnections: 15

但这实际上并没有设置系统级属性;它似乎只是创建了一个应用程序级属性。我已经通过 http://locahost:8080/env 验证了这一点和

比较启动时的 JMX 控制台
java -jar -Dspring.profiles.active=production myapp.jar

对比

java -Dhttp.maxConnections=15 myapp.jar

我想我可以在“生产”配置文件上创建一个 @Conditional 的 bean,它基于我的 application.yml 以编程方式调用 System.setProperty code>--定义的属性,但是有没有更简单的方法单独通过配置文件?

最佳答案

你可以试试。

@Profile("production")
@Component
public class ProductionPropertySetter {

@PostConstruct
public void setProperty() {
System.setProperty("http.maxConnections", "15");
}

}

关于java - 我可以在 Spring Boot 配置文件中定义系统属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36895711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com