spring-boot-maven-plugin >= 1.4.0 jar structure changes

泪湿孤枕 提交于 2019-12-02 02:34:43

问题


I have a spring-boot project where all integration tests are in separate module which starts the application module using spring-boot-maven-plugin during the integration-test phase and executes the suite against it. This construct worked fine until its been upgraded to 1.4.0.RELEASE. Now I get a ClassNotFoundException.

After I checked the "1.4.0" jar structure I figured out that its different than the "1.3.6" one and all the packages are no more on top level but in BOOT-INF etc. folders (see screen shots below) and the class loader can no more find the package defined in the "mainClass".

Does Someone have an idea about fixing it and if this solution is possible in the new version?

Thanks in advance!

jar structure < 1.4.0

jar structure >= 1.4.0

ITest module:

<!-- dependency to the app module -->
<dependency>
    <groupId>com.company.app</groupId>
    <artifactId>app-module</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>
...
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${spring.boot.version}</version>
    <configuration>
        <mainClass>com.company.app.RunServer</mainClass>
    </configuration>
    <executions>
        <execution>
            <id>pre-integration-test</id>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>post-integration-test</id>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Application module:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

回答1:


A solution for how to use a Spring Boot application as a dependency can be found here.

Essentially, in your maven build, add this:

<build>
  <plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <classifier>exec</classifier>
        </configuration>
    </plugin>
  </plugins>
</build>

This will cause your primary jar artifact (the one which would be built in a standard maven build) to be structured normally, so you can depend on it, and the spring-boot-maven-plugin will repackage the jar into a second artifact, this one executable, with the exec classifier.




回答2:


Hm, there've been plenty of changes in testing recently, so did you check the upgrade notes for 1.4.0?




回答3:


There is a nice documentation to change the Class and package names https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes



来源:https://stackoverflow.com/questions/39616970/spring-boot-maven-plugin-1-4-0-jar-structure-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!