Spring Cloud版本更改后,无法构建标准Jar

wenhan he :

我的 ./build.gradle

plugins {
//  id 'org.springframework.boot' version '2.1.4.BUILD-SNAPSHOT'
    id 'org.springframework.boot' version '1.5.9.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'

group = 'com.yd.spring'
version = '1.0.0'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/snapshot' }
    maven { url 'https://repo.spring.io/milestone' }
}

ext {
//  set('springCloudVersion', 'Greenwich.BUILD-SNAPSHOT')
    set('springCloudVersion', 'Edgware.SR2')
}

dependencies {
    implementation 'com.google.code.gson:gson'
    implementation 'redis.clients:jedis'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-web'

    runtimeOnly 'mysql:mysql-connector-java'
    implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0'

    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-zuul'
    implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

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

注释代码是依赖项的版本,然后是版本更改。

更改后,我的想法可以成功运行项目

但是当我建立一个Jar使用命令

./gradlew clean build

是将被打印:

15:43:33: Executing task 'build'...


> Task :compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :processResources
> Task :classes
> Task :findMainClass
> Task :jar
> Task :bootRepackage
> Task :assemble
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses

> Task :test
2019-03-27 15:43:43.837  INFO 31765 --- [       Thread-9] o.s.w.c.s.GenericWebApplicationContext   : Closing org.springframework.web.context.support.GenericWebApplicationContext@7c93dc34: startup date [Wed Mar 27 15:43:37 CST 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@7bb38644
2019-03-27 15:43:43.838  INFO 31765 --- [       Thread-9] o.s.c.n.e.s.EurekaServiceRegistry        : Unregistering application gateway-oauth2-service with eureka with status DOWN
2019-03-27 15:43:43.838  WARN 31765 --- [       Thread-9] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1553672623838, current=DOWN, previous=STARTING]
2019-03-27 15:43:43.839  INFO 31765 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_GATEWAY-OAUTH2-SERVICE/localhost:gateway-oauth2-service:-1: registering service...
2019-03-27 15:43:43.841  INFO 31765 --- [       Thread-9] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 2147483647
2019-03-27 15:43:43.842  INFO 31765 --- [       Thread-9] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 0
2019-03-27 15:43:43.843  INFO 31765 --- [       Thread-9] o.s.c.n.zuul.ZuulFilterInitializer       : Stopping filter initializer
2019-03-27 15:43:43.846  INFO 31765 --- [       Thread-9] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
2019-03-27 15:43:43.847  INFO 31765 --- [       Thread-9] com.netflix.discovery.DiscoveryClient    : Unregistering ...
2019-03-27 15:43:43.851  INFO 31765 --- [       Thread-9] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_GATEWAY-OAUTH2-SERVICE/localhost:gateway-oauth2-service:-1 - deregister  status: 200
2019-03-27 15:43:43.855  INFO 31765 --- [       Thread-9] com.netflix.discovery.DiscoveryClient    : Completed shut down of DiscoveryClient
2019-03-27 15:43:43.864  WARN 31765 --- [       Thread-9] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2019-03-27 15:43:43.864  INFO 31765 --- [       Thread-9] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.

> Task :check
> Task :build

BUILD SUCCESSFUL in 10s
7 actionable tasks: 7 executed
15:43:44: Task execution finished 'build'.

而且输出文件的大小uuGatewayOAuth2-1.0.0.jar只有125KB。

并使用命令运行:

java -jar uuGatewayOAuth2-1.0.0.jar

然后在项目启动时抛出错误:

Exception in thread "main" 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.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
    at com.yd.spring.gatewayoauth2.Application.main(Application.java:17)
    ... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 9 more

为什么?我该如何解决?

Marcin Grzejszczak:

您正在混合版本。对于格林威治发布系列,您需要使用Boot2.1.x。您使用的implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0'依赖项很可能是使用Boot 2.0。因此,通常您需要照顾的版本不匹配。

您可以在https://spring.io/projects/spring-cloud#overview网站的“发行火车”部分下查看发行火车和启动版本的兼容性表

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法在 Spring Boot 上构建可执行 JAR

启动后更改Spring Cloud Config服务器uri

在Spring Cloud Config更改后切换jdbc连接

Spring Cloud Stream Elmhrust.RELEASE 无法更改 Serde

具有 jar 依赖项的 Spring Boot 应用程序在 maven 构建后不会运行

Spring Cloud Kubernetes-启用配置重新加载后,Spring Boot无法启动

需要Spring版本#-仅具有spring.jar文件

如何从 Spring Boot jar 构建 DockerImage

无法构建使用 Spring-boot 开发的应用程序的标记版本:

带有Spring-Cloud的Spring Boot:gradle构建失败

Spring Cloud与Spring Platform BOMs

更新到版本 3.0.3 后,Spring Boot Cloud Vault 不再加载属性

在Spring的构建后阶段之前注入模拟

如何构建Spring Cloud Stream JMS ActiveMQ

Spring Cloud Task无法使用RabbitMQ从Spring Cloud Stream启动

Spring Cloud Data Flow:版本化的流

用于多个服务版本的Spring Cloud发现

微服务系统中的 Spring Cloud 版本

项目构建错误:org.springframework.cloud:'spring-cloud-starter-eureka-server:jar缺少'dependencies.dependency.version'

项目构建错误:'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-sleuth-zipkin:jar is missing

如何解决依赖项错误项目构建错误:缺少依赖项cloud:spring-cloud-starter-openfeign:jar

Spring Boot版本更改导致错误

Spring Cloud Dataflow Server 在本地锁定 Jar

添加Spring执行器依赖项后无法构建项目

由于测试依赖性,Gradle Spring Cloud Stream项目无法构建

Spring Tool Suite 4:更新至版本4.5.0后无法打开项目

使用Maven更新Spring框架版本后,Eclipse的Tomcat服务器将无法启动

Spring Boot 2-更改Jar名称

无法在Spring Boot 2.3.3中构建映像