I have created a Spring Cloud Contract stub in a Spring Boot project (spring-server
). The client that wants to call this stub is not a Spring project and cannot be one. If I run the following in the client:
@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) {
}
}
}
then I get an error
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
Obviously I don't have a @SpringBootConfiguration
, as this isn't a Spring Boot project.
What's the workaround here?