Java 转储springboot配置属性

Java 转储springboot配置属性,java,spring,spring-boot,Java,Spring,Spring Boot,我需要从正在运行的实例中转储springboot应用程序属性,可以吗?我需要它的原因:我正在使用-Dspring.profiles.active=profilea,profileb来链接配置文件,但其中一个属性设置不正确。 谢谢这里是同样的问题: 由此总结:不存在内在机制。但我也很好奇是否有人知道 但当您启动时,您可以获取System.getProperties并将它们打印到日志文件中 package org.example; import org.slf4j.*; import org.s

我需要从正在运行的实例中转储springboot应用程序属性,可以吗?我需要它的原因:我正在使用-Dspring.profiles.active=profilea,profileb来链接配置文件,但其中一个属性设置不正确。 谢谢

这里是同样的问题:

由此总结:不存在内在机制。但我也很好奇是否有人知道

但当您启动时,您可以获取System.getProperties并将它们打印到日志文件中

package org.example;

import org.slf4j.*;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class JwtEvaluatorApplication implements ApplicationRunner {

    Logger log = LoggerFactory.getLogger(getClass());

    public static void main(String[] args) {
        SpringApplication.run(JwtEvaluatorApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<String> cmdArg1 = args.getOptionValues("cmdArg1");
        if (cmdArg1 != null && cmdArg1.size() > 0) {
            System.setProperty("cmdArg1", cmdArg1.get(0));
        }

        logPropeties();
    }

    void logPropeties() {
        for (Object key : System.getProperties().keySet()) {
            log.info(key + ":  " + System.getProperty(key.toString(), "not defined"));
        }
    }
}

我一直在找,没找到这个。ThanksI为您在原始文章中添加了完整的解决方案。看这里:
String cmdArg1 = System.getProperty("cmdArg1");