【问题标题】:spring boot com.sun.jersey.spi.container.servlet.ServletContainerspring boot com.sun.jersey.spi.container.servlet.ServletContainer
【发布时间】:2015-12-19 22:59:53
【问题描述】:

我用 spring-boot 和 jersey 开始了一个新的 maven 项目。调用时出现错误:mvn clean spring-boot:run。

我的 pom.xml 的一部分:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.5.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>

例外:

java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:520)

有什么想法吗? 谢谢

【问题讨论】:

    标签: java spring maven servlets spring-boot


    【解决方案1】:

    您似乎缺少 jersey-server 库。请包括以下内容:-

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.19</version>
    </dependency>
    

    【讨论】:

    • 我没有新的依赖。我有一个带有 web.xml 的 WebContent 文件夹。我删除了它,它现在可以正常工作了。
    • 不!不幸的是,这不是根本原因,至少在我的环境中它没有解决问题。我仍在为此苦苦挣扎。还是谢谢。
    • 正是如此,基线是由于 pom 中的库不匹配或完全没有此 jar,因此该 jar 未在类路径中解析,因此抛出此错误。当你恢复你的 repo 时,应用程序能够找到这个 jar,因此没有抛出任何错误。
    【解决方案2】:

    这个问题有点老了,但是......无论如何,我都会就我在这个问题上的经历发表评论。

    就我而言,我解决了这个问题清理本地~/.m2/repository,让maven(在重新构建EurekaServer时)获取依赖项(这次是正确的)。在那之后,甚至不用碰我的 pom.xml,服务器就开始正常工作了。我认为在我之前的 maven 本地存储库中,得到了一些“干扰”spring-boot 依赖项的东西(因为我们的 maven 存储库曾经充满大量依赖项,导致运行了几个概念验证)。

    【讨论】:

      猜你喜欢
      • 2013-07-21
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      • 1970-01-01
      • 2016-05-15
      • 2014-04-07
      • 2014-04-07
      相关资源
      最近更新 更多