SpringCloud openFeign 报错:feign.FeignException: status 404 reading UserMessageClient

在服务提供commons暴露接口:

@FeignClient(value = "COMMONS",fallback =UserMessageClient.UserMessageClientFallback.class)
public interface UserMessageClient {
    @RequestMapping(value = "/user/sendMessage",method = RequestMethod.POST)
    boolean userLoginByCode(@RequestParam(value = "phone", required = true) String phone);

    @Component
    static class UserMessageClientFallback implements UserMessageClient{

        @Override
        public boolean userLoginByCode(String phone) {
            return false;
        }
    }
}

配置文件:

eureka:
  client:
    service-url:
     defaultZone: http://132.232.173.122:8761/eureka/

在服务调用user上调用接口:

@RestController()
@RequestMapping("/userRegister")
public class HomeController {

    @Autowired
    UserMessageClient userMessageClient;

    @Value("${person.sex}")
    private String dev;
    @PostMapping("/index")
    public ResultVo> index(@Phone @RequestParam String phone, Map map){
        boolean flage=false;
        try {
            flage= userMessageClient.userLoginByCode(phone);
        }catch (Exception e){
            throw new BusinessException(ResultEnum.NO_ACCESS);
        }

        if (!flage) {
            map.put("info", "发送失败");
            return ResultVoUtil.error(ResultEnum.PHONE_SENT_FAIL.getCode(), ResultEnum.PHONE_SENT_FAIL.getMsg());
        }else {
            map.put("info", "发送成功");
            return ResultVoUtil.success(map);
        }


    }

bootstrap.yml文件配置:

spring:
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config
      label: master
      profile: dev
eureka:
  client:
    service-url:
      defaultZone: http://132.232.173.122:8761/eureka/

服务调用是出现feign.FeignException: status 404 reading UserMessageClient

后查是在commons服务上配置了path

server:
  port: 7979
  servlet:
    context-path: /commons

所以在接口的@FeignClient注解上添加path值

@FeignClient(value = "COMMONS", path = "/commons",fallback =UserMessageClient.UserMessageClientFallback.class)
public interface UserMessageClient {
    @RequestMapping(value = "/user/sendMessage",method = RequestMethod.POST)
    boolean userLoginByCode(@RequestParam(value = "phone", required = true) String phone);

    @Component
    static class UserMessageClientFallback implements UserMessageClient{

        @Override
        public boolean userLoginByCode(String phone) {
            return false;
        }
    }
}

解决,记录。

你可能感兴趣的:(springcloud,0->1)