spring无法在rest服务中实例化UriInfo [英] spring can't instantiate UriInfo in rest service

查看:161
本文介绍了spring无法在rest服务中实例化UriInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用UriInfo获取请求参数列表,这是我的代码:

I try to use UriInfo to get the list of request parameters, here is my code :

@RestController public class MyController {
@RequestMapping(value = "/documents", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
 public Object getDocuments( @Context UriInfo uriInfo,  
 @RequestParam(value    = "sta", required = false) String param1,      @RequestParam(value = "sta2", required   = false) String param2){

  MultivaluedMap<String, String> queryParamList = uriInfo.getQueryParameters();

}

此代码导致此异常: org.springframework.beans.BeanInstantiationException:无法实例化[javax.ws.rs.core.UriInfo]:指定的类是接口

this code cause this exception : org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.ws.rs.core.UriInfo]: Specified class is an interface

感谢帮助

推荐答案

这是因为UriInfo不是Spring MVC对象.它是一个JAX-RS对象,您没有使用JAX-RS,而是使用Spring MVC.使用Spring MVC,如果只需要参数映射,则可以使用@RequestParam

It's because UriInfo isn't a Spring MVC object. It is a JAX-RS object and you are not using JAX-RS, you're using Spring MVC. With Spring MVC, if you just want the parameter map, you can just inject it with @RequestParam

public Object getDocuments(@RequestParam MultiValueMap<String, String> requestParams)

请注意,MultiValueMap是Spring类,而不是JAX-RS MultivaluedMap.

Note, the MultiValueMap is a Spring class, it's not the JAX-RS MultivaluedMap.

另请参见:

这篇关于spring无法在rest服务中实例化UriInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆