簡體   English   中英

與澤西島的Spring Cloud合同

[英]Spring Cloud Contract with Jersey

我有一個簡單的項目Spring boot項目。 它包含一個基於Jersey的Controller:@Path(“ persons”)@Produces(MediaType.APPLICATION_JSON)公共類PersonsController {

    @GET
    public Person get() {
        return new Person("James", 20);
    }
}

它按預期返回json響應(URL: http:// localhost:PORT / persons ):

{
  "name": "James",
  "age": 20
}

我的目的是為此控制器添加Spring Cloud Contract測試。 我已經添加了所有必需的mvn配置,並進行了測試:

public class MvcTest {
    @Before
    public void setup() {
        RestAssuredMockMvc.standaloneSetup(new PersonsController());
    }
}

這是合同(常規文件):import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url('persons')
    }
    response {
        status 200
        body(
                "name": "James",
                "age": 20
        )
    }
}

當我運行mvn clean package總是返回以下錯誤:測試失敗:

  ContractVerifierTest.validate_getTest:26 expected:<[200]> but was:<[404]>

我認為這應該與ServletDispatcher有關,因為它看不到Jersey的路徑。 替換為@RequestMapping的@Path的同一項目有效。 但是,我需要使其與Jersey一起使用。 我錯過了什么嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM