2

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?

jar structure < 1.4.0:

enter image description here

jar structure >= 1.4.0:

enter image description here

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>
leopal
  • 4,711
  • 1
  • 25
  • 35
cecode
  • 21
  • 4

3 Answers3

2

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.

Jon O
  • 6,532
  • 1
  • 46
  • 57
0

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

gtonic
  • 2,295
  • 1
  • 24
  • 32
0

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

Srikanta
  • 1,145
  • 2
  • 12
  • 22
  • Thanks for the reply! This is a nice sum up but I doesn't say much more than I already know. I don't see solution for the problem that the class loader can not find my class in the new jar structure. If I use that _classifier_ approach the class is found but the dependencies needed for starting the application are no more available. – cecode Sep 22 '16 at 08:20