Java 将系统属性传递给spring boot

Java 将系统属性传递给spring boot,java,spring,spring-boot,Java,Spring,Spring Boot,我需要使用的库以以下方式读取系统属性: System.getProperty("library.system.property") 启动应用程序时,有没有办法将此类属性传递给spring boot,或者我需要在系统中设置它?您可以在命令行上传递它: java -Dlibrary.system.property=value -jar myapp.jar 如果您使用SpringBootMaven插件执行应用程序,请尝试(无换行) 有关其他详细信息,请参阅。您也可以这样做: public sta

我需要使用的库以以下方式读取系统属性:

System.getProperty("library.system.property")

启动应用程序时,有没有办法将此类属性传递给spring boot,或者我需要在系统中设置它?

您可以在命令行上传递它:

java -Dlibrary.system.property=value -jar myapp.jar 

如果您使用SpringBootMaven插件执行应用程序,请尝试(无换行)


有关其他详细信息,请参阅。您也可以这样做:

public static void main(String[] args) {
    System.setProperty("key", "value");
    SpringApplication.run(MyApplication.class);
}

更新2020-01-08

对于弹簧靴2.2.2.在开发时释放

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dmy_-Dmy_system_properties=test1"
mvn spring-boot:run -Drun.jvmArguments="-Dmy_system_properties=test1"
对于弹簧靴1.5.x.在开发时释放或更低

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dmy_-Dmy_system_properties=test1"
mvn spring-boot:run -Drun.jvmArguments="-Dmy_system_properties=test1"
对于运行方式jar

java -Dmy_system_properties=test1 -jar service.jar 

您可以尝试使用一个可运行的示例,在这里

Put System.setProperty与您说的一样,它可以运行,但我还不明白为什么必须将它放在SpringApplication.run()之前?您在运行应用程序之前设置了一个系统属性。然后在应用程序中可以使用此系统属性。