Can I use Spring's MockMvc with Jersey resources?

假装没事ソ 提交于 2019-12-08 21:38:45

问题


I have successfully integrated Spring and Jersey via Spring Boot' starter POMs, and I have a couple Jersey endpoints. Now I'd like to unit test the resources. I can't seem to get MockMvc working. I get a 404 error when attempting to GET a resource endpoint.

I know there is a Jersey test framework out there, but it appears to launch a server. I'm hoping to avoid "integration" type tests and keep this as simple as possible. Can I do this with MockMvc?


回答1:


Unfortunately doesn't seem to be possible as MockMvc doesn't actually start servlet container.

You can use

  1. RestTemplate to fire requests against server started on localhost. Here are examples from Spring Boot repo: Example 1 and Example 2.
  2. Rest Assured library


来源:https://stackoverflow.com/questions/34644952/can-i-use-springs-mockmvc-with-jersey-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!