找到注解 @EnableCircuitBreaker,但没有实现。你忘了包括一个首发?

Annotation @EnableCircuitBreaker found, but there are no implementations. Did you forget to include a starter?

正在尝试从 SpringBoot + SpringCloud 应用程序构建 ShadowJar。

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;

@EnableCircuitBreaker
@SpringBootApplication
public class App {

    public static void main(String[] args) {
        SpringApplication.run(App.class);
    }

}

应用程序在 IDE 成功启动,但构建和 运行 jar 导致以下错误:

java.lang.IllegalStateException: Annotation @EnableCircuitBreaker found, but there are no implementations. Did you forget to include a starter?
    at org.springframework.cloud.commons.util.SpringFactoryImportSelector.selectImports(SpringFactoryImportSelector.java:76)
    at org.springframework.context.annotation.ConfigurationClassParser$DefaultDeferredImportSelectorGroup.process(ConfigurationClassParser.java:842)
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:828)
    at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:563)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:91)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:692)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:530)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)

Gradle 设置:

plugins {
    id 'java'
    id 'application'
    id "com.github.johnrengelman.shadow" version "4.0.2"
}

sourceCompatibility = 1.10

shadowJar {
    baseName = 'bundle'
    version = '1.0-SNAPSHOT'
    zip64 = true
    manifest {
        attributes 'Main-Class': 'package.App'
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.6.RELEASE'
    compile group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-eureka-client', 
            version: '2.0.2.RELEASE', { exclude group: 'com.google.code.gson', module: 'gson' }
    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-hystrix', version: '2.0.2.RELEASE'
    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth', version: '2.0.2.RELEASE'
    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-zipkin', version: '2.0.2.RELEASE'
    testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.0.6.RELEASE'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

缺少哪个 starter/dependency?

这是我的配置。

        buildscript {
            ext {
                springBootVersion = '2.0.5.RELEASE'
            }
            repositories {
                mavenLocal()
                mavenCentral()

            }
            dependencies {
                classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
            }
        }

        apply plugin: 'java'
        apply plugin: 'eclipse'
        apply plugin: 'org.springframework.boot'
        apply plugin: 'io.spring.dependency-management'

        group = 'com.learning.microservices'
        version = '0.0.1-SNAPSHOT'
        sourceCompatibility = 1.8

        repositories {
            mavenLocal()
            mavenCentral()
        }


        ext {
            springCloudVersion = 'Finchley.SR1'
        }

        dependencies {
            compile('org.springframework.boot:spring-boot-starter-web')
            compile('org.springframework.cloud:spring-cloud-starter-config')
            compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
            compile('org.springframework.cloud:spring-cloud-starter-netflix-hystrix')
            compile('org.springframework.cloud:spring-cloud-starter-sleuth')
            compile('org.projectlombok:lombok:1.16.8')
            compile('org.springframework.boot:spring-boot-starter-actuator')
            compile('com.learning.microservices:interfaces:1.0.0')
            compile('org.springframework.boot:spring-boot-starter-data-jpa')
            runtime('com.h2database:h2')
            testCompile('org.springframework.boot:spring-boot-starter-test')
        }

        dependencyManagement {
            imports {
                mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
            }
        }

您在使用 spring-boot-gradle-plugin 吗?启动 spring 引导云应用程序很有帮助。还要考虑用户 spring 云依赖项。

Here你可以多看看

没有理由不使用 BootJar(而是使用 ShadowJar)来构建 uber-jar。这导致了错误的包装。

这是一个有效的 build.gradle 打包 SpringBoot + SpringCloud uber-jar:

buildscript {
    ext {
        springBootVersion = '2.0.6.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

plugins {
    id 'java'
    id 'application'
    id 'org.springframework.boot' version '2.0.6.RELEASE'
}

sourceCompatibility = 1.10
mainClassName = 'com.App'

bootJar {
    baseName = 'bundle'
    version = '1.0-SNAPSHOT'
    group = 'micro-services'
}

repositories {
    mavenCentral()
}

ext {
    springCloudVersion = '2.0.2.RELEASE'
}

dependencies {
    compile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
    compile "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:${springCloudVersion}", 
            { exclude group: 'com.google.code.gson', module: 'gson' }
    compile "org.springframework.cloud:spring-cloud-starter-netflix-hystrix:${springCloudVersion}"
    compile "org.springframework.cloud:spring-cloud-starter-sleuth:${springCloudVersion}"
    compile "org.springframework.cloud:spring-cloud-starter-zipkin:${springCloudVersion}"
    compile group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
    testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
    testCompile group: 'junit', name: 'junit', version: '4.12'
}