![](/img/trans.png)
[英]How to externalize application.properties files in Spring Boot to e.g. external dependent JAR?
[英]Where are the application.properties files in a spring boot jar?
我有一个带有嵌入式 Tomcat 的 Spring Boot 应用程序 (2.0.1),它已通过 mvn clean package springboot:repackage 组装到一个可执行的 jar 中。 该应用程序运行完美。
我们有一项安全要求,规定使用的密码必须在属性文件中加密。 他们是(与jasypt)。 我正在使用 @ConfigurationProperties 将它们注入到类中。
作为 QA 测试的一部分,测试人员需要查看加密的属性。
我的问题是,当我打开 jar 文件时,我找不到 application.properties 文件。 它们不是装在罐子里的吗? 根据环境在编译时预注入?
pom.xml
<groupId>com.jebrick.rim</groupId>
<artifactId>regulusConnector</artifactId>
<version>1.0-QA-RELEASE</version>
<packaging>jar</packaging>
<name>regulusConnector</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<cxf.version>3.2.5</cxf.version>
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
<tomcat.version>8.5.34</tomcat.version>
<mainClass>com.jebrick.rim.App</mainClass>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!--<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>-->
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.0.1.RELEASE</version>
<optional>true</optional>
</dependency>
more dependencies
<build>
<resources>
<resource>
<directory>resources</directory>
<targetPath>src/main/java/resources</targetPath>
<includes>
<include>*.properties</include>
</includes>
</resource>
</resources>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.jebrick.rim.App</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<!-- Force alphabetical order to have a reproducible build -->
<runOrder>alphabetical</runOrder>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
application.properties 文件位于 JAR 文件中:
BOOT-INF\classes\application.properties
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.