【发布时间】:2018-12-11 14:36:05
【问题描述】:
我有一个 Spring Boot 应用程序,它监视和重新部署另一个 Spring Boot 应用程序。两个应用程序都使用application.properties 文件进行配置,但是当主应用程序重新部署另一个以防万一发生故障时,辅助应用程序不会获取其自己的application.properties 的配置。
辅助应用程序配置了一个 Spring 启动执行器端点,当主应用程序重新部署时,它没有被激活(我想是因为它自己的 application.properties 没有被拾取)。为了启用执行器端点,应该选择这些行:
endpoints.metrics.enabled=true
endpoints.metrics.id=metrics
endpoints.metrics.sensitive=false
从主应用程序的角度来看,这是我通过 java 代码执行的命令:
bash -c 'java -jar full_path_to_the_jar_file' &
并尝试将-Dspring.config.location=file:full_path_to_appliction.properties_file 添加到此命令中,但没有任何区别。
这是用来执行重新部署的java类是这样的:
package com.my.package;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public class ProcessExecutor {
private static final Logger LOGGER =
LoggerFactory.getLogger(ProcessExecutor.class);
private final String command;
public ProcessExecutor(String command) {
Validate.notBlank(command);
this.command = command;
}
public void execute() {
LOGGER.debug("Command that will be executed: {}",
this.command);
CommandLine commandLine = CommandLine.parse(this.command);
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
executor.execute(commandLine);
} catch (IOException e) {
LOGGER.error("Error restarting the process: {}",
e.getMessage());
}
}
}
当同一命令单独运行时,它会正常工作并加载application.properties 文件中的所有值。如何从主应用程序正确重新部署 jar?
【问题讨论】:
标签: java spring spring-boot