spring boot 向环境添加另一个属性文件

sta*_*ack 5 java spring properties

我想知道除了 application.properties 文件之外,是否可以将另一个属性文件添加到环境路径中。如果是这样,您如何指定新路径?因此,您可以使用 Autowired Environment 变量访问属性。目前在我的 java 项目中,默认属性文件 application.properties 的路径为 /soctrav/src.main.resources/application.properties

小智 5

如果您想在没有命令行参数的情况下执行此操作,则可以解决此问题。

@SpringBootApplication
@PropertySources({
        @PropertySource("classpath:application.properties"),
        @PropertySource("classpath:anotherbunchof.properties")
})
public class YourApplication{

}
Run Code Online (Sandbox Code Playgroud)


lub*_*nac 3

您可以使用命令行参数指定其他属性文件:

java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
Run Code Online (Sandbox Code Playgroud)

查看应用程序属性文件 Spring Boot 文档章节