我可以将Spring的MockMvc与Jersey资源一起使用吗? [英] Can I use Spring's MockMvc with Jersey resources?
本文介绍了我可以将Spring的MockMvc与Jersey资源一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经通过Spring Boot的入门级POM成功地集成了Spring和Jersey,并且有几个Jersey端点.现在,我想对资源进行单元测试.我似乎无法使MockMvc工作.尝试获取资源端点时收到404错误.
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.
我知道那里有一个Jersey测试框架,但是它似乎可以启动服务器.我希望避免集成"类型测试,并使其尽可能简单.我可以用MockMvc做到这一点吗?
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?
推荐答案
不幸的是,由于您可以使用
-
RestTemplate
向本地主机上启动的服务器发出请求.以下是Spring Boot回购中的示例:示例2 . - Rest Assured 库
RestTemplate
to fire requests against server started on localhost. Here are examples from Spring Boot repo: Example 1 and Example 2.- Rest Assured library
这篇关于我可以将Spring的MockMvc与Jersey资源一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文