【发布时间】:2018-10-08 08:53:59
【问题描述】:
我在 Spring Boot 项目 (spring-server) 中创建了 Spring Cloud Contract 存根。想要调用此存根的客户端不是 Spring 项目,也不能是 Spring 项目。如果我在客户端运行以下命令:
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureStubRunner(ids = {"uk.co.hadoopathome:spring-server:+:stubs:8093"},
stubsMode = StubRunnerProperties.StubsMode.LOCAL)
public class ContractTest {
@Test
public void testContractEndpoint() {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet("http://localhost:8093/ac01");
CloseableHttpResponse response = httpclient.execute(httpGet);
String entity = EntityUtils.toString(response.getEntity());
assertEquals("ac01returned", entity);
response.close();
} catch (IOException ignored) {
}
}
}
然后我得到一个错误
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
显然我没有@SpringBootConfiguration,因为这不是 Spring Boot 项目。
这里有什么解决方法?
【问题讨论】:
标签: java spring spring-boot spring-cloud-contract