Spring Download useTestClasspath raises CannotLoadBeanClassException and ClassNotFoundException

I have a maven project with a test class located in src/test/java/MyDevClasswhich is for development / testing purposes only. I would like to use it when I run spring-boot-maven-plugin with the command line mvn spring-boot:run.

So my pom.xmlcontains:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <!-- TODO: Will create a maven profile and have useTestClasspath only for development/testing -->
                <useTestClasspath>true</useTestClasspath>
            </configuration>
        </plugin>
    </plugins>
</build>

But I get the following error:

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [MyDevClass]
Caused by: java.lang.ClassNotFoundException: MyDevClass

Interestingly, I have another project using tomcat7-maven-plugin and it works fine:

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.0</version>
            <configuration>
                <useTestClasspath>true</useTestClasspath>
            </configuration>
        </plugin>

What am I missing?

+4
source share
1 answer

Spring -boot maven plugin ( ) classpath, useTestClasspath true.

(-X Maven), JVM. .

sources ( 1.5.3 ), useTestClasspath addDependencies.

  • <folders>

    <folders>
      <folder>${project.build.testOutputDirectory}</folder>
    </folders>
    

    , , .

  • Maven <scope>test</scope>.
+1

Source: https://habr.com/ru/post/1658033/


All Articles