我可以在单独的类中使Hystrix全局回退功能吗?

问题描述

假设我有以下控制器:

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "globalHandler.payment_Global_FallbackMethod")
public class OrderHystirxController
{
    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="1500")
    })
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id)
    {
        return "aaa";
    }
}

在这里,输入代码

@DefaultProperties(defaultFallback = "globalHandler.payment_Global_FallbackMethod")

我想表达的意思是,创建一个带有Payment_Global_FallbackMethod函数的GlobalHandler类组件,尝试让其他控制器共享使用它。有可能吗?

import org.springframework.stereotype.Component;

@Component
public class GlobalHandler
{
    public String payment_Global_FallbackMethod()
    {
        return "[GlobalHandler][payment_Global_FallbackMethod],Global level fallback";
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...