我可以在单独的类中创建hystrix全局回退函数吗?

db2dz4w8  于 2021-07-05  发布在  Java
关注(0)|答案(0)|浏览(297)

假设我有以下控制器:

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\u global\u fallbackmethod函数创建一个globalhandler类组件,尝试让其他控制器共享它。有可能吗?

import org.springframework.stereotype.Component;

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

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题