gradle HTTP错误500请求失败,

qc6wkl3g  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(121)

此问题在此处已有答案

Jersey stopped working with InjectionManagerFactory not found(7个答案)
上个月关门了。
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  See: http://docs.oracle.com/cd/E28613_01/web.1211/b65890/web_xml.htm
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         id="WebApp_ID" version="3.0">
    <servlet>
        <servlet-name>JerseyApp</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>path.to.package.MainClass</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>JerseyApp</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

我的主要课程:

@ApplicationPath("/")
public class MainClass extends ResourceConfig
{

   public MainClass() {
      // Add a package used to scan for components.
      packages(this.getClass().getPackage().getName());
   }
}

控制器和主类位于同一个包中。

@Path("/abc")
public class LabelController
{

   @GET
   @Produces(MediaType.APPLICATION_JSON)
   public List<ABC> getResources(@QueryParam("something") List<String> ids)
   {

Build.gradle:

buildscript {
    ext {
        LOMBOK_VERSION = "1.18.22"
        JAVAX_WSRS_VERSION = "2.1.1"
    }
}

plugins {
    id "org.gretty" version "4.0.3"
}

apply plugin: 'java-library'
apply plugin: 'java'
apply plugin: 'war'

repositories {
    mavenLocal()
    maven {
        another intern repositories
    }
}

dependencies {
    compileOnly "org.projectlombok:lombok:${LOMBOK_VERSION}"
    testImplementation "org.projectlombok:lombok:${LOMBOK_VERSION}"
    annotationProcessor "org.projectlombok:lombok:${LOMBOK_VERSION}"

    implementation "com.microsoft.sqlserver:mssql-jdbc:9.4.1.jre11"

    implementation "javax.ws.rs:javax.ws.rs-api:${JAVAX_WSRS_VERSION}"
    implementation 'org.glassfish.jersey.core:jersey-server:3.0.8'
    implementation 'org.glassfish.jersey.containers:jersey-container-servlet:3.0.8'
}

当我用./gradlew appRun运行应用程序并调用url http://localhost:8080/myservice时,我得到了这个错误。
错误:

HTTP ERROR 500 jakarta.servlet.ServletException: JerseyApp==org.glassfish.jersey.servlet.ServletContainer@80f88154{jsp=null,order=-1,inst=true,async=false,src=DESCRIPTOR:file:///C:/Projects/JerseyApp/build/inplaceWebapp/WEB-INF/web.xml,STARTED}
URI:    /myservice/
STATUS: 500
MESSAGE:    jakarta.servlet.ServletException: JerseyApp==org.glassfish.jersey.servlet.ServletContainer@80f88154{jsp=null,order=-1,inst=true,async=false,src=DESCRIPTOR:file:///C:/Projects/JerseyApp/build/inplaceWebapp/WEB-INF/web.xml,STARTED}
SERVLET:    JerseyApp
CAUSED BY:  jakarta.servlet.ServletException: JerseyApp==org.glassfish.jersey.servlet.ServletContainer@80f88154{jsp=null,order=-1,inst=true,async=false,src=DESCRIPTOR:file:///C:/Projects/JerseyApp/build/inplaceWebapp/WEB-INF/web.xml,STARTED}
CAUSED BY:  java.lang.IllegalStateException: InjectionManagerFactory not found.
Caused by:
jakarta.servlet.ServletException: JerseyApp==org.glassfish.jersey.servlet.ServletContainer@80f88154{jsp=null,order=-1,inst=true,async=false,src=DESCRIPTOR:file:///C:/Projects/JerseyApp/build/inplaceWebapp/WEB-INF/web.xml,STARTED}
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:651)
    at org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:486)
    at org.eclipse.jetty.servlet.ServletHolder.prepare(ServletHolder.java:731)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:524)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:578)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:223)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1571)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1375)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1544)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1297)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:149)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
    at org.eclipse.jetty.server.Server.handle(Server.java:562)
    at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
    at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
    at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1038)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalStateException: InjectionManagerFactory not found.
    at org.glassfish.jersey.internal.inject.Injections.lambda$lookupInjectionManagerFactory$0(Injections.java:74)
    at java.base/java.util.Optional.orElseThrow(Optional.java:403)
    at org.glassfish.jersey.internal.inject.Injections.lookupInjectionManagerFactory(Injections.java:74)
    at org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:69)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:261)
    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:339)
    at jakarta.servlet.GenericServlet.init(GenericServlet.java:178)
    at org.eclipse.jetty.servlet.ServletHolder$Wrapper.init(ServletHolder.java:1305)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:633)
    ... 29 more

我和Intellij一起工作

yvgpqqbh

yvgpqqbh1#

我添加了以下依赖项:implementation 'org.glassfish.jersey.inject:jersey-hk2:3.0.8'

相关问题