使用Spring Boot Maven插件时,jar文件中缺少Spring Boot应用程序中的资源

Jan*_*yne 10 java spring maven spring-boot spring-boot-maven-plugin

我使用Spring-Boot v1.3.0.M5和Maven v3.3.3.我曾经能够使用此命令从控制台运行我的Spring Boot(启动)应用程序.

mvn clean package spring-boot:run

但是,我不得不修改我pom.xml的帐户以适应不同的环境构建.特别是,我使用Maven配置文件来修改启动应用程序的属性文件.现在,当我运行前面提到的命令时,启动应用程序无法运行并抱怨以下异常.

引起:java.lang.NumberFormatException:对于输入字符串:"$ {MULTIPART.MAXREQUESTSIZE}"

我有一个属性文件位于src/main/resources/config/application.properties.此属性文件有一堆键值对,如下所示.

multipart.maxFileSize=${multipart.maxFileSize}
multipart.maxRequestSize=${multipart.maxRequestSize}
Run Code Online (Sandbox Code Playgroud)

然后在我的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>
Run Code Online (Sandbox Code Playgroud)

我注意到如果我输入mvn clean package并查看jar文件内部,application.properties文件就在jar中.

但是,如果我输入mvn clean package spring-boot:run,那么该applications.properties文件不在 jar中.事实上,没有任何东西src/main/resources使它成为jar文件.

这个问题对我来说有点烦人,因为如果我想从命令行运行我的启动应用程序,我现在必须做两个步骤.

  1. mvn clean package
  2. java -jar ./target/app-0.0.1-SNAPSHOT.jar

关于我做错了什么的任何想法?

Ste*_*oll 10

文档中所述,在 类路径前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>
Run Code Online (Sandbox Code Playgroud)