0

Resilience4j 版本:1.1.0

Java版本:1.8.0_221

问题描述:我正在尝试将 Resilience4j 与 WebFlux 一起使用。

我添加了以下依赖项,但尚未添加任何 Resilience4j 特定代码:

<dependency>
    <groupId>io.github.resilience4j</groupId>
    <artifactId>resilience4j-reactor</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
    <groupId>io.github.resilience4j</groupId>
    <artifactId>resilience4j-spring-boot2</artifactId>
    <version>1.1.0</version>
</dependency>

启动服务器时出现以下错误:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:558)
    at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.IllegalStateException: Cannot load configuration class: io.github.resilience4j.bulkhead.autoconfigure.BulkheadAutoConfiguration
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses (ConfigurationClassPostProcessor.java:413)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory (ConfigurationClassPostProcessor.java:253)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors (PostProcessorRegistrationDelegate.java:286)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors (PostProcessorRegistrationDelegate.java:130)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors (AbstractApplicationContext.java:705)
    at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:531)
    at com.walmartlabs.example.ExampleAppContext.<init> (ExampleAppContext.java:55)
    at com.walmartlabs.example.Example_Main.main (Example_Main.java:150)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:558)
    at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
4

3 回答 3

1

弹性 4j 具有多种功能,如断路器、重试、速率限制器、隔板。

如果您不想要所有这些功能并且只想要回退机制,请继续在 pom.xml 文件中添加以下依赖项:

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-aop</artifactId>
            </dependency>
            <dependency>
                <groupId>io.github.resilience4j</groupId>
                <artifactId>resilience4j-reactor</artifactId>
                <version>1.2.0</version>
                <exclusions>
                    <exclusion>
                        <groupId>io.github.resilience4j</groupId>
                        <artifactId>resilience4j-ratelimiter</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>io.github.resilience4j</groupId>
                        <artifactId>resilience4j-bulkhead</artifactId>
                    </exclusion>
                    <exclusion>
                        <artifactId>io.github.resilience4j</artifactId>
                        <groupId>resilience4j-timelimiter</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>io.github.resilience4j</groupId>
                <artifactId>resilience4j-spring-boot2</artifactId>
                <version>1.2.0</version>
                <exclusions>
                    <exclusion>
                        <groupId>io.github.resilience4j</groupId>
                        <artifactId>ratelimiter</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>io.github.resilience4j</groupId>
                        <artifactId>bulkhead</artifactId>
                    </exclusion>
                    <exclusion>
                        <artifactId>io.github.resilience4j</artifactId>
                        <groupId>timelimiter</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
于 2020-06-12T12:29:29.850 回答
0

错过了下面的依赖。

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-aop</artifactId>
            </dependency>
于 2022-02-03T18:14:33.537 回答
0

尝试将 <spring-cloud.version>2020.0.2</spring-cloud.version> 更改为 <spring-cloud.version>2020.0.1</spring-cloud.version>

于 2021-04-12T21:26:18.410 回答