前言
公司项目进行微服务改造,由之前的dubbo改用SpringCloud,微服务之间通过FeignClient进行调用,今天在测试的时候,eureka注册中心有相应的服务,但feignclient就是无法调通,一直报404错误,排查过程如下:
一、问题:
服务提供方定义的接口如下:
/** * 黑白名单查询接口 * * @author LiJunJun * @since 2018/10/18 */@Component(value = "blackAndWhiteListFeignClient")@FeignClient(value = "pear-cache-service", path = "v1/cache/limitlist")public interface IBlackAndWhiteListFeignClient { /** * 获取黑白名单手机号分组编号 * * @param trace 请求流水 * @param phoneNum 电话号码 * @return 电话号码所在分组 */ @RequestMapping(value = "/blackAndWhiteList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) ResultData<String> blackAndWhiteList(@RequestHeader(name = "Trace") String trace, @RequestParam("phoneNum") String phoneNum);}
接口实现类如下:
/** * 黑白名单controller * * @author LiJunJun * @since 2018/10/18 */@ProtectedLdApi@RestController@RequestMapping(value = "v1/cache/limitlist")@Api(value = "黑白名单缓存", description = "黑白名单缓存相关接口")public class BlacklAndWhiteListController extends AbstractController implements IBlackAndWhiteListFeignClient { /** * 日志记录器 */ private final static Log LOGGER = new Log(BlacklAndWhiteListController.class); /** * 注入tedis */ @Autowired private JedisSentinelPoolExt jedisSentinelPool; /** * 获取黑白名单手机号分组编号 * * @param trace 请求流水 * @param phoneNum 电话号码 * @return 电话号码所在分组 */ @Override @ApiOperation(value = "获取黑白名单手机号分组编号", notes = "根据电话号码从缓存中获取黑白名单分组") @RequestMapping(value = "/blackAndWhiteList", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResultData<String> blackAndWhiteList(@RequestHeader(name = "Trace") String trace, @RequestParam("phoneNum") String phoneNum) { do something... }}
调用方如下:
public class MessageListController { private static final Log LOGGER = new Log(MessageListController.class); @Autowired private IBlackAndWhiteListFeignClient blackAndWhiteListFeignClient; @RequestMapping(value = "/testBlackAndWhiteList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResultData<String> testBlackAndWhiteList() { LOGGER.info("开始调用缓存接口"); ResultData<String> res = blackAndWhiteListFeignClient.blackAndWhiteList("asdqwezxxc", "B18037903086"); LOGGER.info("调用结果:" + res.getResultData()); return res; }
调用结果:
华丽丽的404了,很头疼,经过各种度娘,发现导致这个问题有两个原因,以下是解决方法:
二、问题分析
经过百度,说将SpringBoot配置文件里面 server.servlet.context-path
新闻热点
疑难解答