尝试运行jar文件时出现NoClassDefFoundError错误

3

我的代码编译没有问题,但是当我尝试运行我的Jar文件时,在堆栈跟踪中出现了以下错误:

java.lang.IllegalStateException: Error processing condition on org.springframework.cloud.stream.config.codec.kryo.KryoCodecAutoConfiguration
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.stream.config.ChannelBindingAutoConfiguration] from ClassLoader       [org.springframework.boot.loader.LaunchedURLClassLoader@439f5b3d]

Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/actuate/endpoint/AbstractEndpoint
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.actuate.endpoint.AbstractEndpoint

我已经在我的pom.xml中添加了actuator作为一个依赖项。以下是所有的依赖项:
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-amqp</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka-streams</artifactId>
        <version>1.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
</dependencies>

我错过了什么吗?这可能是因为我正在使用的Spring Boot版本导致的吗?
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
</parent>

我也想了解这个执行器是从哪里出现在画面中的,因为我在这个虚拟项目中只有两个类。

package demo.example.jobIDProcessor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.integration.annotation.Transformer;
@EnableBinding(Processor.class)
@SpringBootApplication
public class JobIDProcessorApplication {

 @Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
    public String fetchJD(String jobID) {
        return "ye raha JD of "+jobID;
    }

public static void main(String[] args) {
    SpringApplication.run(JobIDProcessorApplication.class, args);
}
}

并且以下内容

package demo.example.jobIDProcessor;

import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.integration.annotation.Transformer;


@EnableBinding(Processor.class)
public class JobIDProcessorConfig {
 @Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
    public String fetchJD(String jobID) {
        return "ye raha JD of "+jobID;
    }
}

这个 "org/springframework/boot/actuate/endpoint/AbstractEndpoint" 是从哪里调用的?

看起来你正在构建一个Spring Cloud Stream应用程序。你能否编辑帖子,展示所有的依赖项?还有一件事。除了Actuator之外,你还需要添加spring-boot-starter-web,以便通过HTTP访问Actuator端点。 - Sabby Anandan
是的,我正在尝试使用Spring Cloud数据流。我已经添加了spring-boot-starter-web,但仍然出现相同的错误。 - frigocat
奇怪!有几个问题: 1)KryoCodecAutoConfiguration在Spring Cloud Stream 2.0中已经不存在了;它曾经在1.3.x版本中出现 - 不确定为什么您的堆栈跟踪中出现了它。 2)您似乎正在使用Rabbit binder,但您还有KStreams库 - 为什么您不能直接使用KStream binder呢? - Sabby Anandan
1
为了清晰起见,请从Initializr下载一个全新的应用程序,使用Rabbit binder并将其打包成uber-jar。请按照快速入门中的说明进行操作。一旦通过java -jar ...单独运行成功,它也将在SCDF中正常工作。 - Sabby Anandan
现在运行得非常好!在我的原始演示中,我添加了RabbitMQ和kafka作为依赖项。但是现在当我从头开始创建单独的应用程序时,它可以正常工作!感谢@SabbyAnandan - frigocat
1个回答

0

这主要与您正在使用的云流依赖版本有关。请尝试在pom.xml中添加以下内容。

 <dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-dependencies</artifactId>
            <version>Fishtown.BUILD-SNAPSHOT</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/libs-snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

这将指向 cloud-stream-dependencies 的最新版本,该版本引用了正确的 actuator 版本


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接