java.lang.NoSuchMethodError:org.glassfish.hk2.api.ServiceLocatorFactory.creat-泽西岛

时间:2018-08-25 21:54:41

标签: java maven jersey http-status-code-500

我正在为我的项目制作第一个简单的RESTFul API,并且正在使用Maven。首先,我使用默认API创建了Maven原型jersey-quickstart-webapp。我已经添加了文件,添加了依赖项。但是,当我使用API​​ URL时:localhost:8080 / webapi / myresource->我在这里遇到500个错误:

HTTP状态500 –内部服务器错误

类型异常报告

用于Servlet [Jersey Web应用程序]的消息Servlet.init()抛出异常

说明服务器遇到意外状况,阻止其满足请求。

例外

javax.servlet.ServletException:Servlet [Jersey Web应用程序]的Servlet.init()引发异常     org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)     org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)     org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)     org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)     org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)     org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)     org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:806)     org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1498)     org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)     java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)     java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知源)     org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     java.lang.Thread.run(未知来源)

根本原因

java.lang.NoSuchMethodError:org.glassfish.hk2.api.ServiceLocatorFactory.create(Ljava / lang / String; Lorg / glassfish / hk2 / api / ServiceLocator; Lorg / glassfish / hk2 / extension / ServiceLocatorGenerator; Lorg / glassfish / hk2 / api / ServiceLocatorFactory $ CreatePolicy;)Lorg / glassfish / hk2 / api / ServiceLocator;     org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.createLocator(AbstractHk2InjectionManager.java:114)     org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager。(AbstractHk2InjectionManager.java:86)     org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager。(ImmediateHk2InjectionManager.java:62)     org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory $ Hk2InjectionManagerStrategy $ 1.createInjectionManager(Hk2InjectionManagerFactory.java:79)     org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory.create(Hk2InjectionManagerFactory.java:97)     org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:93)     org.glassfish.jersey.server.ApplicationHandler。(ApplicationHandler.java:282)     org.glassfish.jersey.servlet.WebComponent。(WebComponent.java:335)     org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178)     org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370)     javax.servlet.GenericServlet.init(GenericServlet.java:158)     org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)     org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)     org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)     org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)     org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)     org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)     org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:806)     org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1498)     org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)     java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)     java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知源)     org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     java.lang.Thread.run(未知来源)

注意服务器日志中提供了根本原因的完整堆栈跟踪。 Apache Tomcat / 8.5.33

这是我的pom.xml文件的样子:     http://maven.apache.org/maven-v4_0_0.xsd“>

<modelVersion>4.0.0</modelVersion>

<groupId>org.glassfish.jersey.archetypes</groupId>
<artifactId>ParkingSystem</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ParkingSystem</name>

<build>
    <finalName>ParkingSystem</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <inherited>true</inherited>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>${jersey.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
     <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.glassfish.hk2</groupId>
        <artifactId>hk2-api</artifactId>
        <version>2.5.0-b42</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
        <!-- artifactId>jersey-container-servlet</artifactId -->
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.inject</groupId>
        <artifactId>jersey-hk2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-binding</artifactId>
    </dependency>
</dependencies>
<properties>
    <jersey.version>2.27</jersey.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

我正在使用Netbeans和Tomcat。我以为该错误是由于缺少hk2-api依赖性引起的,但是添加后没有任何改变。

1 个答案:

答案 0 :(得分:1)

好的,我找到了解决方案。我的错!我错误地复制了在开始使用Maven之前手动下载的库。删除所有这些.jar文件后,一切开始工作。抱歉,这很糟糕,问题可以解决。