【发布时间】:2016-10-17 19:44:07
【问题描述】:
我有一个 Maven 项目,其测试类位于 src/test/java/MyDevClass,仅用于开发/测试目的。我想在使用命令行mvn spring-boot:run 启动spring-boot-maven-plugin 时使用它。
所以,我的pom.xml 包含:
<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>
但是,我收到以下错误:
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [MyDevClass]
Caused by: java.lang.ClassNotFoundException: MyDevClass
有趣的是,我有另一个使用tomcat7-maven-plugin 的项目,它工作正常:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<useTestClasspath>true</useTestClasspath>
</configuration>
</plugin>
我错过了什么?
【问题讨论】:
-
我不明白。当它是测试类时,为什么要在生产环境中注册它?没有意义。
-
嗨@luboskrnac。正确,我不希望它在生产中。我将为此创建一个 Maven 配置文件。
-
嗨斯蒂芬尼科尔,没问题。为了简单起见,我保留了默认包。