【问题标题】:Spring Boot No Class found error though starter dependency has added classes in classpath尽管启动器依赖项在类路径中添加了类,但 Spring Boot No Class found 错误
【发布时间】:2018-07-13 08:43:34
【问题描述】:

尽管在类路径中有适当的 jar,但 Spring Boot 抛出 - java.lang.ClassNotFoundException: org.apache.camel.spring.spi.XmlCamelContextConfigurer

这里缺少的任何建议。

我已经在 pom.xml 中添加了相应的启动器,如下所示:

    <dependency>
        <groupId>org.springframework.boot</groupId>[![enter image description here][1]][1]
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-cxf</artifactId>
        <version>2.19.3</version>
    </dependency>

项目 maven 依赖项还显示了类的可用性,如给定的图像附件中所示。

【问题讨论】:

  • @peeTechs 为什么同一个 2.19.3、2.20.1 有两个版本?请参阅左侧窗格中的依赖项列表。会不会是这个问题?
  • 此外,我相信有一种方法可以在控制台中查看类路径(也许通过单击 ... 那里)。检查是否存在所需的库。
  • 你是对的 Rajind - 我刚刚注意到在下面评论了我的答案。谢谢

标签: spring-boot noclassdeffounderror


【解决方案1】:

答案就在这里——https://stackoverflow.com/a/34271507/2885422 这完全取决于 maven 加载类的方式。类路径中有 2 个版本的 camel-spring.jars(2.20.1 和 2.19.3。参考:我的原始帖子图片) 而 org.apache.camel.spring.spi.XmlCamelContextConfigurer 类仅在 2.20.1 jar 中可用。并且默认情况下,maven 会在较早的一个中查找,一旦找到匹配的包但没有找到类就会抛出错误(?)

我相信 2.19.3 被加载的原因是 Apache-cxf jars 是 2.19.3。不幸的是,我们的项目存储库没有 apache-cxf starter jars。

https://stackoverflow.com/a/34271507/2885422

解决方案: - 希望对以后的参考有所帮助 通过添加选项,我可以通过添加排除条款来解决问题,如下所示。因此,我只能加载所需的版本 jar。

<dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-cxf</artifactId>
        <version>2.19.3</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-spring</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 2017-01-05
    • 1970-01-01
    • 2018-09-29
    • 1970-01-01
    • 2022-08-20
    相关资源
    最近更新 更多