我正在尝试为位于1.5.X.上的Spring引导应用程序实现Spring Cloud合约
我添加了以下依赖项:
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>${spring-cloud-contract.version}</version>
<extensions>true</extensions>
<configuration>
<packageWithBaseClasses>com.example</packageWithBaseClasses>
</configuration>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-verifier</artifactId>
<version>${spring-cloud-contract.version}</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
<dependencies>
<!-- all dependencies -->
<!-- you can exclude rest-assured from spring-cloud-contract-verifier -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
我已经创建了我的基类如下:
BaseClass.java
@RunWith(SpringRunner.class)
@SpringBootTest(classes=MySpringBootApplication.class)
public abstract class BaseClass {
@Autowired
MyController myController;
//Mock Dependencies
RestAssuredMockMVC.standaloneSetup(myController)
}
我可以看到测试是按预期由spring合同生成的(基于yml合同(,我的构建失败了,错误如下:
java.lang.noclassdeffounderror org/springframework/boot/context/properties/bind/binder
at org.springframework.cloud.function.compiler.config.FunctionProxyApplicationListener.bind(FunctionProxyApplicationListener.java:120)
at org.springframework.cloud.function.compiler.config.FunctionProxyApplicationListener.onApplicationEvent(FunctionProxyApplicationListener.java:87)
at org.springframework.cloud.function.compiler.config.FunctionProxyApplicationListener.onApplicationEvent(FunctionProxyApplicationListener.java:48)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster:122)
.......
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.bind.Binder
您使用的spring-cloud合约版本与该版本的spring-boot不兼容。这就是为什么你会得到类未找到异常