简介:用于转
这个问题是非常相似How to put a directory first on the classpath with Spring Boot?和我搜索了一下周围可惜没有迄今为止的工作。在spring-boot-maven-plugin
中都没有更改为packaging=ZIP
,也没有使用loader.path
,如boot features external config或how to - properties and configuration中所解释的,所以我必须缺少一些东西。还有一件事,如果可能的话,我想避免将每个配置文件作为参数传递给file://...
。
我当初是几种类型的服务的模拟器应用程序:SFTP,肥皂等,最初,它支持的每个服务器类型通过一个属性文件配置的1个实例。
我已经更新它以支持不同端口上的多个服务器实例,并且配置在YAML文件中完成,并且我也从经典弹簧迁移到引导。最后,应用程序交付为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
推出主类添加config
目录到classpath,春季将加载属性文件没有任何问题:
java <other args> -cp "..." com.whatever.SimulatorLauncher
由于迁移,现在启动产生的罐子,所以不再使用的-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;
因为它们的配置应该更新,而无需重新打包应用程序,所有文件都从所得的罐排除,但在包装的rpm下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>
任何帮助或提示是不胜感激。