org.apache.catalina.core.standardwrappervalve.invoke servlet[jersey rest service]java.lang.nullpointerexceptio的分配异常

8mmmxcuj  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(696)

我试着在那里寻找教程,但我找不到任何可以解决我的问题。希望有人能帮忙,谢谢。我试着向泽西提出一个get请求,我得到的是:

12-Dec-2020 20:34:27.342 SEVERE [http-nio-8080-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet [Jersey REST Service]
    java.lang.NullPointerException
        at org.glassfish.jersey.inject.cdi.se.CdiSeInjectionManager.getInstanceInternal(CdiSeInjectionManager.java:152)
        at org.glassfish.jersey.inject.cdi.se.CdiSeInjectionManager.getInstance(CdiSeInjectionManager.java:142)
        at org.glassfish.jersey.internal.inject.ProviderBinder.bindProvider(ProviderBinder.java:76)
        at org.glassfish.jersey.server.ResourceModelConfigurator.bindProvidersAndResources(ResourceModelConfigurator.java:189)
        at org.glassfish.jersey.server.ResourceModelConfigurator.init(ResourceModelConfigurator.java:87)
        at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:365)
        at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$1(ApplicationHandler.java:316)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
        at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:232)
        at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:315)
        at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:282)
        at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
        at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154)
        at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:346)
        at javax.servlet.GenericServlet.init(GenericServlet.java:158)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1144)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
        at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:763)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:615)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1626)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)

我的 project.iml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="FacetManager">
    <facet type="web" name="Web">
      <configuration>
        <descriptors>
          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
        </descriptors>
        <webroots>
          <root url="file://$MODULE_DIR$/web" relative="/" />
        </webroots>
      </configuration>
    </facet>
  </component>
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" scope="PROVIDED" name="Tomcat 8.5.57" level="application_server_libraries" />
    <orderEntry type="library" name="JAX-RS-2.0" level="project" />
    <orderEntry type="module-library">
      <library name="JUnit4">
        <CLASSES>
          <root url="jar://$USER_HOME$/.m2/repository/junit/junit/4.12/junit-4.12.jar!/" />
          <root url="jar://$USER_HOME$/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
        </CLASSES>
        <JAVADOC />
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="library" name="javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.1" level="project" />
    <orderEntry type="library" name="org.glassfish.jersey.containers:jersey-container-servlet:2.26" level="project" />
    <orderEntry type="library" name="org.glassfish.jersey.inject:jersey-hk2:2.26" level="project" />
  </component>
</module>

我的 web.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <display-name>Test REST</display-name>
    <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>main.service</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
 <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

处理请求的类:

@Path("rest/theater")
public class TheaterServiceDbAccessImpl implements TheaterService {
    @GET
    @Produces(MediaType.TEXT_HTML)
    public String helloWorld() {
        return "Hello world";
    }
}

我用intellij和tomcat版本8.x运行这个应用程序。

tzxcd3kk

tzxcd3kk1#

我已经明白我遇到的问题了。所以,当我按照教程,我不小心包括一个 @Path 类定义上方的注解。所以编译程序时,只要把复杂的错误和 NullPointerException 另外,你需要先申报 Path 为了班级。对我来说,应该是 @Path("/rest") ,并且在我想要获得关于剧院的信息的方法之上,我需要包括 @Path("/theater") . 比如说, http://localhost:8080/rest/theater 会给我 Hello world . 就我而言,我不知道这是不是真的。

相关问题