1
我創建了一個非常簡單的Spring啓動應用程序,並使用1.4版本附帶的一些新測試功能測試它。春季開機測試未能加載
應用程序運行正常,大部分測試都是如此,不包括具有新註釋的應用程序。
@SpringBootTest
我不斷收到一個「失蹤EmbeddedServletContainerFactory豆」,根據我見過的其他問題是與不具有以下依賴「彈簧引導起動網」的問題,但我在我的朋友。
下面是失敗的測試代碼和我的pom.xml。
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DataJpaTest
public class BookControllerIT {
@Autowired
private TestRestTemplate restTemplate;
@Autowired
private BookRepository bookRepository;
@Test
public void shouldRetrieveBook(){
bookRepository.save(new Book("Java"));
final ResponseEntity<Book> result = restTemplate.getForEntity("/books/{bookName}", Book.class, "Java");
assertThat(result.getStatusCode(), equalTo(HttpStatus.OK));
assertThat(result.getBody().getName(), equalTo("Java"));
}
}
下面是pom。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.scottlogic</groupId>
<artifactId>library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>library</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
希望得到任何幫助。
刪除'@ DataJpaTest' ...'@ DataJpaTest'(及其他)和'@ SpringBootTest'是互斥的。 –
非常感謝,它做到了。 – wybourn