java - Spring 应用程序运行失败

标签 java spring spring-boot gradle build.gradle

我可以通过 ./gradlew build -x test 成功构建我的代码,但是,当我启动我的应用程序时,它显示

java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V

下面是我的 build.gradle 的依赖:
buildscript {
    repositories {
        mavenLocal()
        maven {
            url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
        }
        mavenCentral()
        jcenter()
    }
    ext {
        projectVersion = '1.3.0-RELEASE'
        grpcVersion = '1.6.1'
        protobufVersion = '3.3.0'
        protobufGradlePluginVersion = '0.8.0'
        springCloudConsulVersion = '1.2.1.RELEASE'
        springBootVersion = '2.0.5.RELEASE'
    }

    dependencies {
        classpath "gradle.plugin.com.liferay:gradle-plugins-node:4.3.0"
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
configurations {
    providedRuntime
    compile.exclude module: 'spring-boot-starter-tomcat'
    all*.exclude module: 'spring-boot-starter-logging'
}

dependencies {       
    compile("org.springframework.boot:spring-boot-starter-web"){
        exclude module: "spring-boot-starter-tomcat"
    }
    compile "org.springframework.cloud:spring-cloud-starter-consul-discovery:${springCloudConsulVersion}"
    compile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '3.1.5.RELEASE'
    compile('org.hibernate:hibernate-validator:5.4.1.Final')
}

我认为这可能是那些版本的问题,但我不确定。另一方面,我发现的大多数解决方案都是 marven,我的应用程序的启动是这样的:
@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class Main {
    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }
}

最佳答案

您正在使用绑定(bind)到 Spring Boot 1.5 的 Spring Cloud 1.2。您已定义使用 Spring Boot 2.0,因此同一框架的 jar 版本不兼容。

接下来,您还手动包含了 elasticsearch 依赖项,而不是使用 Spring Boot 提供的启动器,可能又会引入另一个不兼容的 Spring 版本。

简而言之,你的依赖是一团糟。为选定的 Spring Boot 版本或副版本使用正确的 Spring Cloud 版本。所以要么将 Spring Cloud 版本升级到 2.x 版本,要么降低你正在使用的 Spring Boot 版本。

最后添加spring-boot-starter-data-elasticsearch而不是 spring-data-elasticsearch依赖有一个正确管理的版本。

关于java - Spring 应用程序运行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55737064/

相关文章:

java - Spring Context 启动时打印应用程序横幅

java - Spring Boot 中的 DispatcherServlet 和 web.xml

java.lang.VerifyError : Stack map does not match the one at exception handle

java - 在 Android Studio 中找不到符号类 vector

java - 如何优雅地停止java进程?

java - 创建类路径资源中定义的名为 'entityManagerFactory' 的 bean 时出错 - SO 的解决方案不起作用

java - 深度复制应该如何工作?

spring - 运行 Spring Boot 应用程序时出现数据源错误

spring-boot - 如何在 Spring-Boot 中自定义 MappingMongoConverter (setMapKeyDotReplacement) 而不会破坏自动配置?

java - 如何使用过滤器进行分页