spring boot hystrix integration

时间:2016-12-19 16:36:54

标签: spring-boot hystrix

我有以下方法

@HystrixCommand(commandKey="operator",fallbackMethod="getFakeResponse",commandProperties = {
        @HystrixProperty(name = "hystrix.command.operator.execution.isolation.thread.timeoutInMilliseconds", value = "30000")
})
public String getResponse(){

    try {
        Thread.sleep(6000000l);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
    //  e.printStackTrace();
    }


    return "the real thing";
}

当我尝试运行单元测试代码进行测试时,我得到以下异常

  

com.netflix.hystrix.contrib.javanica.exception.HystrixPropertyException:无法设置命令属性。 groupKey:' HystrixComponentPOC',commandKey:' operator',threadPoolKey:''       at com.netflix.hystrix.contrib.javanica.command.GenericSetterBuilder.build(GenericSetterBuilder.java:88)       在com.netflix.hystrix.contrib.javanica.command.AbstractHystrixCommand。(AbstractHystrixCommand.java:52)       在com.netflix.hystrix.contrib.javanica.command.GenericCommand。(GenericCommand.java:35)       在com.netflix.hystrix.contrib.javanica.command.HystrixCommandFactory.create(HystrixCommandFactory.java:44)       at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.methodsAnnotatedWithHystrixCommand(HystrixCommandAspect.java:85)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)       at java.lang.reflect.Method.invoke(Unknown Source)       在org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:629)       在org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:618)       在org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)       在org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)       在org.springframework.aop.framework.CglibAopProxy $ DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)       在com.masary.topup.HystrixComponentPOC $$ EnhancerBySpringCGLIB $$ 95f9b3dd.getResponse()       在com.masary.topup.refactor.LedgerUpdateTestCases.test(LedgerUpdateTestCases.java:50)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)       at java.lang.reflect.Method.invoke(Unknown Source)       在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:50)       在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)       在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)       在org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)       在org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)       在org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)       在org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)       在org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)       在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)       在org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)       在org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)       在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)       在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)       在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)       在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)       在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)       在org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)       在org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)       在org.junit.runners.ParentRunner.run(ParentRunner.java:363)       在org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)       在org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)       在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)   引起:java.lang.IllegalArgumentException:未知命令属性:hystrix.command.operator.execution.isolation.thread.timeoutInMilliseconds       at com.netflix.hystrix.contrib.javanica.conf.HystrixPropertiesManager.initializeProperties(HystrixPropertiesManager.java:125)       at com.netflix.hystrix.contrib.javanica.conf.HystrixPropertiesManager.initializeCommandProperties(HystrixPropertiesManager.java:99)       at com.netflix.hystrix.contrib.javanica.command.GenericSetterBuilder.build(GenericSetterBuilder.java:86)       ......还有47个

但是,当我删除注释并添加

时,我可以使用例外行为成功运行它
  

hystrix.command.operator.execution.isolation.thread.timeoutInMilliseconds = 30000

到我的属性文件

顺便说一下我唯一的配置是我的主类上的@EnableHystrix,我使用的是spring boot 1.4.0.RELEASE

有什么帮助吗?

1 个答案:

答案 0 :(得分:0)