gpt4 book ai didi

java - 在 Spring Boot 应用程序中更改 application.properties 名称

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:36:10 26 4
gpt4 key购买 nike

我有我的 application.properties/资源中的文件。我只想将名称更改为 <my-project-name>.properties .根据this reference ,我应该能够通过将 spring.config.name 指定为环境属性来更改名称:

java -jar myproject.jar --spring.config.name=myproject

但有没有办法通过注释或在我的代码库中以某种方式做到这一点?

最佳答案

我认为最简单的方法是在 Spring Boot 应用程序入口点的主要方法中设置系统属性:

@SpringBootApplication
public class MyApplication {

public static void main(String[] args) {
// Tell Boot to look for my-project.properties instead of application.properties
System.setProperty("spring.config.name", "my-project");
SpringApplication.run(MyApplication.class, args);
}
}

关于java - 在 Spring Boot 应用程序中更改 application.properties 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42064164/

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