找不到类[org.springframework.boot.autoconfigure.condition.Condit



我使用intellij和Java 1.8来运行我的springboot

我已经尝试在我的代码中创建这样的主jar:

@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
private DemoMetricReaderWriter demoMetricReaderWriter = new DemoMetricReaderWriter();
@Bean
@ExportMetricReader
@ExportMetricWriter
DemoMetricReaderWriter getReader() {
return demoMetricReaderWriter;
}
@RequestMapping("/")
String home() throws Exception {
long start = System.currentTimeMillis();
// insert up to 2 second delay for a wider range of response times
Thread.sleep((long) (Math.random() * 2000));
// let that delay become the gauge.bar metric value
long barValue = System.currentTimeMillis() - start;
demoMetricReaderWriter.updateMetrics(barValue);
return "Hello World!";
}
}

但是当我构建并运行我的jar时,我得到了这样的错误。我试着修复但是我不知道这个

到底是什么问题
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.example.demo.DemoApplication]; nested exception is java.lang.IllegalArgumentException: Could not find class [org.springframework.boot.autoconfigure.condition.ConditionalOnJava$JavaVersion]

这是我的gradle。创建这个应用程序。

plugins {
id 'org.springframework.boot' version '2.5.1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
jar {
manifest {
attributes 'Main-Class': 'com.example.demo.DemoApplication'
}
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'ch.qos.logback', module: 'logback-classic'
}
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
google()
}
dependencies {
// spring boot
implementation ('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
implementation 'org.springframework.boot:spring-boot-starter-undertow'
implementation 'org.springframework.boot:spring-boot-starter-validation'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
// health check
implementation 'org.springframework.boot:spring-boot-actuator:1.5.14.RELEASE'
// logging
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
implementation 'com.lmax:disruptor:3.4.2'
// database
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.5.5'
runtimeOnly 'com.oracle.ojdbc:ojdbc8'
runtimeOnly 'org.postgresql:postgresql'

//datadog
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'org.apache.httpcomponents:httpclient:4.5.3'
implementation 'org.springframework.boot:spring-boot-actuator:1.5.14.RELEASE'

// lombok
compileOnly 'org.projectlombok:lombok'

// testing
testImplementation 'org.mockito:mockito-core:3.9.0'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'io.projectreactor:reactor-test'
annotationProcessor 'org.projectlombok:lombok'
}
test {
useJUnitPlatform()
}

我的问题是我的代码有什么问题?为了运行这段代码,我使用gradle,我已经尝试使用互联网的例子,但仍然得到错误....如何解决这个问题?

与包含ConditionalOnJava的模块存在依赖冲突。ConditionalOnJavaspring-boot-autoconfigure模块的一部分。让我们看看Gradle选择了哪个版本。为此,我们发出以下命令:

gradlew -q dependencyInsight --dependency spring-boot-autoconfigure --configuration runtimeClasspath

我们的相关输出是

org.springframework.boot:spring-boot-autoconfigure:1.5.14.RELEASE -> 2.5.1
--- org.springframework.boot:spring-boot-actuator:1.5.14.RELEASE
--- runtimeClasspath

这告诉我们spring-boot-actuator:1.5.14.RELEASE依赖于spring-boot-autoconfigure:1.5.14.RELEASEConditionalOnJava确实包含1.15.14.RELEASE版本的子类JavaVersion(ConditionalOnJava$JavaVersion是错误信息的一部分)。然而,Gradle也告诉我们,spring-boot-actuator已经升级到2.5.1,并且这个版本不再包含子类JavaVersion了。

恐怕您需要将Spring Boot Actuator升级到与您正在运行的Spring Boot版本相关的版本:

implementation 'org.springframework.boot:spring-boot-starter-actuator'

通过Micrometer与starterio.micrometer:micrometer-registry-datadog发送致动器度量到Datadog,详细信息请参见致动器度量文档。

相关内容

  • 没有找到相关文章

最新更新