尝试从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)
成绩设置:
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'
}
缺少哪个启动程序/依赖项?
答案 0 :(得分:1)
这是我的配置。
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 boot cloud应用程序很有帮助。还请考虑向用户提供Spring Cloud依赖项。
Here,您可以详细了解一下。
答案 1 :(得分:0)
没有理由不使用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'
}