关于fegin 没进入 fallback 以及Hystrix Dashboard 监控界面没出图形的解决方式

   <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

Dalston.RELEASE

**版本中
使用 fegin做 服务调用,发现当 服务提供这,提供服务时候,没有进入 fallback,
需要加,**

feign:
   hystrix:
     enabled: true

调通的代码如下

controller

@RestController
@RequestMapping(value = "/sys/user")
public class UserLoginController {
    @Autowired
    private UserLoginService userLoginService;
    @Autowired
    private JwtService jwtService;


    @RequestMapping(value = "/login/{username}/{password}",method = RequestMethod.GET)
    public ReturnDTO login(@PathVariable("username") String username, @PathVariable("password") String password) {
        ReturnDTO returnDTO = new ReturnDTO();
        Map<String, Object> message = new HashMap<String, Object>();
        boolean isSuccess = userLoginService.login(username, password);

        if (isSuccess) {
            String token = jwtService.createJWT(username, 1);
            returnDTO.setCode(true);
            message.put("token", token);
            returnDTO.setMessage(message);
        } else {
            returnDTO.setCode(false);
        }
        return returnDTO;
    }

service

@FeignClient(value = "jwt-service")
public interface JwtService {

    @RequestMapping(value = "/create",method = RequestMethod.GET)
     String createJWT(@RequestParam(value = "username")String username, @RequestParam(value = "id")Integer id);

}



@FeignClient(value ="${userlogin.name}" ,fallback = UserLoginServiceHystrix.class)
public interface UserLoginService {

   @RequestMapping(value = "${userlogin.url}",method = RequestMethod.GET)
    Boolean login(@RequestParam(value = "username")  String username, @RequestParam(value = "password")  String password);
}



@Component
 class UserLoginServiceHystrix implements UserLoginService {

    @Override
    public Boolean login(@RequestParam(value = "username") String username, @RequestParam(value = "password") String password) {
        return false;
    }
}

配置文件

server:
  port: 9002

eureka:
  client:
    service-url:
      defaultZone: http://10.10.8.101:9000/eureka/

spring:
  application:
    name: sys-user-consumer
  messages:
    fallback-to-system-locale: true
management:
  security:
    enabled: false


userlogin:
  name: sys-user-service
  url: /sys/user/login

feign:
   hystrix:
     enabled: true

博客小福利 阿里云优惠券 点我免费领取

我的官网
这里写图片描述

我的官网http://guan2ye.com

我的CSDN地址http://blog.csdn.net/chenjianandiyi

我的简书地址http://www.jianshu.com/u/9b5d1921ce34

我的githubhttps://github.com/javanan

我的码云地址https://gitee.com/jamen/

阿里云优惠券https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=vf2b5zld&utm_source=vf2b5zld

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值