[英]Spring Cloud Contract with Jersey
I have a simple project Spring boot project. 我有一个简单的项目Spring boot项目。 It contains one Jersey based Controller: @Path("persons") @Produces(MediaType.APPLICATION_JSON) public class PersonsController { 它包含一个基于Jersey的Controller:@Path(“ persons”)@Produces(MediaType.APPLICATION_JSON)公共类PersonsController {
@GET
public Person get() {
return new Person("James", 20);
}
}
It returns json response as expected (url: http://localhost:PORT/persons ): 它按预期返回json响应(URL: http:// localhost:PORT / persons ):
{
"name": "James",
"age": 20
}
My aim is to add Spring Cloud Contract tests for this controller. 我的目的是为此控制器添加Spring Cloud Contract测试。 I have added all required mvn configurations, and test: 我已经添加了所有必需的mvn配置,并进行了测试:
public class MvcTest {
@Before
public void setup() {
RestAssuredMockMvc.standaloneSetup(new PersonsController());
}
}
Here is contract (groovy file): import org.springframework.cloud.contract.spec.Contract 这是合同(常规文件):import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method 'GET'
url('persons')
}
response {
status 200
body(
"name": "James",
"age": 20
)
}
}
When I run mvn clean package
following error always is returned: Failed tests: 当我运行mvn clean package
总是返回以下错误:测试失败:
ContractVerifierTest.validate_getTest:26 expected:<[200]> but was:<[404]>
I believe this should be related to the ServletDispatcher as it doesn't see Jersey's paths. 我认为这应该与ServletDispatcher有关,因为它看不到Jersey的路径。 The same project with replaced @Path to @RequestMapping works. 替换为@RequestMapping的@Path的同一项目有效。 However, I need to make it working with Jersey. 但是,我需要使其与Jersey一起使用。 Have I missed something? 我错过了什么吗?
Have you checked the section about jaxrs support? 您是否查看了有关jaxrs支持的部分? https://cloud.spring.io/spring-cloud-contract/1.0.x/spring-cloud-contract.html#_jax_rs_support . https://cloud.spring.io/spring-cloud-contract/1.0.x/spring-cloud-contract.html#_jax_rs_support 。 Here you have an example how you can use it https://github.com/spring-cloud/spring-cloud-contract/tree/1.0.x/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject 这里有一个示例如何使用它https://github.com/spring-cloud/spring-cloud-contract/tree/1.0.x/spring-cloud-contract-tools/spring-cloud-contract-gradle-插件/ src目录/测试/资源/ functionalTest / sampleJerseyProject
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.