在SpringCloud使用feign接口远程调用微服务时出现以下错误
报错: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: The expression ‘array’ evaluated to a null value.] with root cause
org.apache.ibatis.builder.BuilderException: The expression ‘array’ evaluated to a null value.
错误说明:参数并未传入到方法中
原因:在自动注入feign接口实例时候,feign接口中的方法并未获取到参数,导致微服务中的形参列表为空,从而查询异常,如图:参数为空
错误feign接口:
微服务controller:
解决办法:在feign接口中设置相应注解@Requestparam
总结!!!:
feign接口中的接口方法,就好比是远程服务提供者Controller中的Hander方法(只不过如同本地调用
了),那么在进行参数绑定的时,可以使用@PathVariable、@RequestParam、@RequestHeader
等,这也是OpenFeign对SpringMVC注解的支持,但是需要注意value必须设置,否则会抛出异常