我用Spring Boot编写了一个REST API,并将其打包为WAR文件。我将WAR复制到Tomcat 8的webapps
文件夹并启动了tomcat服务。当服务器启动时,它会引发一些由以下原因引起的异常:
java.lang.TypeNotPresentException:Type org.springframework.test.context.ContextConfiguration不存在
我稍微解决了这个问题并发现如果我将webapp的lib上的JAR文件和lib提供的文件夹移动到Tomcat8 / lib文件夹,则不会抛出异常并且API按预期工作。我不知道是什么导致了这个问题。我对pom.xml
有一些依赖关系,其范围为provided
。也许他们给我带来了问题。
这是我的pom:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.pp</groupId>
<artifactId>DAO-Commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.pp</groupId>
<artifactId>carddao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.pp</groupId>
<artifactId>cardtemplatedao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.pp</groupId>
<artifactId>cardlibrarydao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>