【问题标题】:Can not bootrun due to run build.gradle file由于运行 build.gradle 文件而无法启动
【发布时间】:2019-10-14 22:15:43
【问题描述】:

我是 Spring 世界的新手,刚刚将 pom.xml 更新为 gradle 以管理所有依赖项。

gradle 被社区抛弃了吗? 另外,这个错误的可能根本原因是什么。

刚刚意识到 Spring boot 有很多令人困惑的错误消息。我真的不认为这种错误消息会帮助任何开发人员。 这种错误有什么想法或方向吗?

我只知道我将 pom.xml 更改为 gradle 并手动迁移配置文件。 非常感谢!

线程“main”java.lang.AbstractMethodError 中的异常:接收器类 org.springframework.boot.context.config.ConfigFileApplicationListener 未定义或继承已解析方法抽象的实现 supportsSourceType(Ljava/lang/Class;)Z接口 org.springframework.context.event.SmartApplicationListener.

分级

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

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

group = 'dev.15house'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}


dependencies {
    compile group: 'org.modelmapper', name: 'modelmapper', version: '2.1.1'
    compile group: 'org.springframework', name: 'spring-context', version:'4.3.2.RELEASE'
    compile group: 'org.springframework', name: 'spring-webmvc', version:'4.3.2.RELEASE'
    compile("org.springframework.boot:spring-boot-starter-jetty:1.3.5.RELEASE")
    compile("org.springframework.boot:spring-boot-starter-web:1.3.5.RELEASE")
    compile('mysql:mysql-connector-java')
    compile('org.springframework.boot:spring-boot-starter')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-test')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.restdocs:spring-restdocs-mockmvc')
    compile('org.springframework.security:spring-security-test')
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version:'2.9.4'
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version:'2.9.4'
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:'2.9.4'
    runtime group: 'org.webjars', name: 'angularjs', version:'1.5.7'
    runtime group: 'org.webjars', name: 'bootstrap', version:'3.3.7'
}

调试日志

> Task :bootRun FAILED
Exception in thread "main" java.lang.AbstractMethodError: Receiver class org.springframework.boot.context.config.ConfigFileApplicationListener does not define or inherit an implementation of the resolved method abstract supportsSourceType(Ljava/lang/Class;)Z of interface org.springframework.context.event.SmartApplicationListener.
        at org.springframework.context.event.GenericApplicationListenerAdapter.supportsSourceType(GenericApplicationListenerAdapter.java:79)
        at org.springframework.context.event.AbstractApplicationEventMulticaster.supportsEvent(AbstractApplicationEventMulticaster.java:282)
        at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:214)
        at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:185)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:342)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
        at dev.house.XprojApplication.main(XprojApplication.java:14)

【问题讨论】:

  • 您正在混合相互不兼容的库。 docs.spring.io/spring-boot/docs/current/reference/htmlsingle/…Spring Boot 的每个版本都与 Spring Framework 的基本版本相关联。我们强烈建议您不要指定其版本。基本上其他所有内容都相同:您不能在使用 boot 2.1.9 的应用程序中使用版本为 1.3.5.RELEASE 的 spring boot 启动器.阅读 gradle 插件文档。
  • gradle 是否被社区抛弃了? 不,完全没有。但是,如果您以错误的方式使用它,每个软件都不会做它应该做的。
  • 刚刚意识到 Spring boot 有很多令人困惑的错误消息。我真的不认为这种错误消息会对任何开发人员有所帮助。 这不是 Spring Boot 错误消息。这是 JVM 抛出的 java.lang.AbstractMethodError 消息,因为您使用的类彼此不兼容。

标签: java spring spring-boot gradle


【解决方案1】:

我建议您根据here 的需要生成项目。

Here 你有你需要的依赖。

这是生成的 build.gradle

plugins {
    id 'org.springframework.boot' version '2.1.9.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtimeOnly 'mysql:mysql-connector-java'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-05
    • 2021-07-08
    • 1970-01-01
    • 1970-01-01
    • 2019-10-16
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多