spring can't instantiate UriInfo in rest service

百般思念 提交于 2019-12-20 04:29:26

问题


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();

}

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

thanks for help


回答1:


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)

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

See also:

  • Spring MVC - How to get all request params in a map in Spring controller?


来源:https://stackoverflow.com/questions/42250519/spring-cant-instantiate-uriinfo-in-rest-service

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