如何解决我可以在单独的类中使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 举报,一经查实,本站将立刻删除。