我是 Spring 世界的新手,刚刚将 pom.xml 更新到 gradle 中以管理所有依赖项。
gradle 被社区抛弃了吗? 另外,导致此错误的可能根本原因是什么。
刚刚意识到 Spring boot 有很多令人困惑的错误消息。我真的不认为这种错误消息会对任何开发人员有帮助。 对于这种错误有什么想法或方向吗?
我只知道我将 pom.xml 更改为 gradle 并手动迁移配置文件。 非常感谢!
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.
Gradle
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)
最佳答案
我建议您根据您的需求从 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'
}
关于java - 由于运行 build.gradle 文件而无法启动运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58384708/