我正在使用 Spring-Boot v1.3.0.M5 和 Maven v3.3.3。我以前可以使用这个命令从控制台运行我的 Spring Boot (boot) 应用程序。
mvn clean package spring-boot:run
但是,我不得不修改我的 pom.xml
以适应不同的环境构建。特别是,我正在使用 Maven 配置文件来修改启动应用程序的属性文件。现在,当我运行前面提到的命令时,启动应用程序无法运行并提示以下异常。
Caused by: java.lang.NumberFormatException: For input string: "${MULTIPART.MAXREQUESTSIZE}"
我有一个位于 src/main/resources/config/application.properties
的属性文件。这个属性文件有一堆键值对,如下所示。
multipart.maxFileSize=${multipart.maxFileSize}
multipart.maxRequestSize=${multipart.maxRequestSize}
然后在我的pom.xml
中,我的构建定义如下。
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<!-- development -->
<profile>
<id>env-dev</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>env</name>
<value>dev</value>
</property>
</activation>
<properties>
<multipart.maxFileSize>250MB</multipart.maxFileSize>
<multipart.maxRequestSize>250MB</multipart.maxRequestSize>
</properties>
</profile>
<!-- staging -->
<profile>
<id>env-stg</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>env</name>
<value>stg</value>
</property>
</activation>
<properties>
<multipart.maxFileSize>500MB</multipart.maxFileSize>
<multipart.maxRequestSize>500MB</multipart.maxRequestSize>
</properties>
</profile>
<profiles>
我注意到,如果我输入 mvn clean package
并查看 jar
文件,application.properties
文件在 jar 中.
但是,如果我输入 mvn clean package spring-boot:run
,那么 applications.properties
文件在 jar 中是 not .事实上,src/main/resources
下的任何内容都不会进入 jar 文件。
这个问题对我来说有点烦人,因为如果我想从命令行运行我的启动应用程序,我现在必须执行两个步骤。
mvn clean package
java -jar ./target/app-0.0.1-SNAPSHOT.jar
关于我做错了什么有什么想法吗?
最佳答案
作为 described in the documentation mvn spring-boot:run
在你的类路径前添加 src/main/resources
以默认支持热重载。您可以轻松关闭此功能
<build>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.2.7.RELEASE</version>
<configuration>
<addResources>false</addResources>
</configuration>
</plugin>
...
</plugins>
...
</build>
关于java - 使用 Spring Boot Maven 插件时,jar 文件中缺少 Spring Boot 应用程序中的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33197230/