rpm 的外部化配置
Externalized configuration for rpm
简介:
这个问题与 How to put a directory first on the classpath with Spring Boot? and I've searched around a bit but unfortunately nothing worked so far. Neither changing to packaging=ZIP
in the spring-boot-maven-plugin
nor using loader.path
as explained in boot features external config or how to - properties and configuration 非常相似,所以我一定漏掉了什么。还有一件事,如果可能的话,我想避免将每个配置文件作为 file://...
.
的参数传递
我有一个应用程序,它最初是几种服务类型的模拟器:sftp、soap 等。最初它支持每种服务器类型的 1 个实例,可通过属性文件进行配置。
我现在更新它以支持不同端口上的多个服务器实例,配置是在 YAML 文件中完成的,我还从 classic spring 迁移到引导.最后,应用程序作为 RPM 交付,具有以下结构
installation-dir
|--bin
| '-- simulator.sh [lifecycle management script]
|--config
| |--application.properties
| |--log4j2.xml
| |--samples [sample files for various operations]
| | |-- sample1.csv
| | |-- sample2.csv
| | '-- sample3.csv
| |--simulators.yaml [simulators config]
| '--simulator.jks
|--lib
| '-- simulator-1.0.jar
'--log
'-- simulator.log
之前,simulators.sh
启动主 class 将 config
目录添加到 class 路径,并且 spring 将加载属性文件而没有任何问题:
java <other args> -cp "..." com.whatever.SimulatorLauncher
自迁移以来,它现在启动生成的 jar,因此不再使用 -cp
,我无法让它获取配置文件:
java <other args> lib/simulator-1.0.jar
略微忽略它找不到 aplication.properties
的事实,模拟器的配置加载如下:
@Configuration
@ConfigurationProperties(locations = {"classpath:/simulators.yml"}, ignoreUnknownFields = false, prefix = "simulators")
public class SimulatorSettings {
private static final Logger log = LoggerFactory.getLogger(SimulatorSettings.class);
@NotNull
private List<SftpSettings> sftp;
@NotNull
private List<SoapSettings> soap;
由于无需重新打包应用程序即可更新配置,所有文件都从生成的 jar 中排除,但打包在 config
:
下的 rpm 中
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<excludes>
<!-- these files will be included in the rpm under config -->
<exclude>application.properties</exclude>
<exclude>log4j2.xml</exclude>
<exclude>samples/**</exclude>
<exclude>simulators.yml</exclude>
<exclude>simulator.jks</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.whatever.SimulatorLauncher</mainClass>
<layout>ZIP</layout>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1.5</version>
...
<configuration>
...
<mapping>
<directory>${rpm.app.home}/config</directory>
<sources>
<source>
<location>src/main/resources</location>
<includes>
<include>application.properties</include>
<include>simulators.yml</include>
<include>log4j2.xml</include>
<include>nls-sim.jks</include>
</includes>
</source>
</sources>
<filemode>755</filemode>
</mapping>
非常感谢任何帮助或提示。
我最终删除了 spring-boot-maven-plugin
以防止重新打包,并使用我的工件及其依赖项创建了 RPM 并像以前一样启动应用程序:
java <other args> -cp "<installation dir>/config:...:<libs>" com.whatever.SimulatorLauncher
不过,我还是很想知道是否有人知道使用 spring 引导重新打包的 jar 的方法...
简介:
这个问题与 How to put a directory first on the classpath with Spring Boot? and I've searched around a bit but unfortunately nothing worked so far. Neither changing to packaging=ZIP
in the spring-boot-maven-plugin
nor using loader.path
as explained in boot features external config or how to - properties and configuration 非常相似,所以我一定漏掉了什么。还有一件事,如果可能的话,我想避免将每个配置文件作为 file://...
.
我有一个应用程序,它最初是几种服务类型的模拟器:sftp、soap 等。最初它支持每种服务器类型的 1 个实例,可通过属性文件进行配置。
我现在更新它以支持不同端口上的多个服务器实例,配置是在 YAML 文件中完成的,我还从 classic spring 迁移到引导.最后,应用程序作为 RPM 交付,具有以下结构
installation-dir
|--bin
| '-- simulator.sh [lifecycle management script]
|--config
| |--application.properties
| |--log4j2.xml
| |--samples [sample files for various operations]
| | |-- sample1.csv
| | |-- sample2.csv
| | '-- sample3.csv
| |--simulators.yaml [simulators config]
| '--simulator.jks
|--lib
| '-- simulator-1.0.jar
'--log
'-- simulator.log
之前,simulators.sh
启动主 class 将 config
目录添加到 class 路径,并且 spring 将加载属性文件而没有任何问题:
java <other args> -cp "..." com.whatever.SimulatorLauncher
自迁移以来,它现在启动生成的 jar,因此不再使用 -cp
,我无法让它获取配置文件:
java <other args> lib/simulator-1.0.jar
略微忽略它找不到 aplication.properties
的事实,模拟器的配置加载如下:
@Configuration
@ConfigurationProperties(locations = {"classpath:/simulators.yml"}, ignoreUnknownFields = false, prefix = "simulators")
public class SimulatorSettings {
private static final Logger log = LoggerFactory.getLogger(SimulatorSettings.class);
@NotNull
private List<SftpSettings> sftp;
@NotNull
private List<SoapSettings> soap;
由于无需重新打包应用程序即可更新配置,所有文件都从生成的 jar 中排除,但打包在 config
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<excludes>
<!-- these files will be included in the rpm under config -->
<exclude>application.properties</exclude>
<exclude>log4j2.xml</exclude>
<exclude>samples/**</exclude>
<exclude>simulators.yml</exclude>
<exclude>simulator.jks</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.whatever.SimulatorLauncher</mainClass>
<layout>ZIP</layout>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1.5</version>
...
<configuration>
...
<mapping>
<directory>${rpm.app.home}/config</directory>
<sources>
<source>
<location>src/main/resources</location>
<includes>
<include>application.properties</include>
<include>simulators.yml</include>
<include>log4j2.xml</include>
<include>nls-sim.jks</include>
</includes>
</source>
</sources>
<filemode>755</filemode>
</mapping>
非常感谢任何帮助或提示。
我最终删除了 spring-boot-maven-plugin
以防止重新打包,并使用我的工件及其依赖项创建了 RPM 并像以前一样启动应用程序:
java <other args> -cp "<installation dir>/config:...:<libs>" com.whatever.SimulatorLauncher
不过,我还是很想知道是否有人知道使用 spring 引导重新打包的 jar 的方法...