问题
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
RestTemplate
to fire requests against server started on localhost. Here are examples from Spring Boot repo: Example 1 and Example 2.- Rest Assured library
来源:https://stackoverflow.com/questions/34644952/can-i-use-springs-mockmvc-with-jersey-resources