我正在尝试在我的Java应用程序中使用Hystrix,它是Non spring java应用程序。
在POM中使用以下Maven依赖项来启用Hystrix命令:
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-javanica</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.12</version>
</dependency>
<dependency>
<groupId>com.netflix.rxjava</groupId>
<artifactId>rxjava-core</artifactId>
<version>0.20.7</version>
</dependency>
使用以下依赖项来启用AspectJ:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.7</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>
使用以下配置在META-INF中创建aop.xml:
<aspectj>
<aspects>
<aspect name="com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect" />
</aspects>
<weaver options="-verbose">
<include within="*" />
</weaver>
</aspectj>
我的服务类别中使用过的Hystrix命令:
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
@Component
@Service
public class TestHystrix
@HystrixCommand(commandKey = "testHystrix", threadPoolKey = "testHystrix", commandProperties = {
@HystrixProperty(name = "hystrix.command.testHystrix.execution.isolation.thread.timeoutInMilliseconds", value = "30") }, threadPoolProperties = {
@HystrixProperty(name = "hystrix.threadpool.testHystrix.maximumSize", value = "3") })
public void testHystrix() {
添加了以下JVM参数:
-DWeavingMode=compile
但是在Junit测试和应用程序运行时,都会导致以下错误:
java.lang.NoSuchMethodError: com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.aspectOf()Lcom/netflix/hystrix/contrib/javanica/aop/aspectj/HystrixCommandAspect;
请帮忙。
喵喵时光机
相关分类