Jersey ServletContainer 仍在尝试使用 javax

问题描述 投票:0回答:1

我正在尝试更新一个应用程序,使其在支持 Jakarta EE 10 的 Tomcat 10.1.26 上运行,并使用

jakarta.*
包命名。

在 Tomcat 中部署时,我因

javax.*
包命名而收到此错误。

org.apache.catalina.core.StandardContext.loadOnStartup Servlet [JerseyContainer] in web application [/myApplication] threw load() exception
        java.lang.ClassNotFoundException: javax.ws.rs.core.Feature
                at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
                at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1144)
                at java.base/java.lang.ClassLoader.defineClass1(Native Method)
                at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1023)
                at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
                at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2302)
                at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:787)
                at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1296)
                at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1144)
                at org.glassfish.jersey.server.ResourceConfig.scanClasses(ResourceConfig.java:891)
                at org.glassfish.jersey.server.ResourceConfig._getClasses(ResourceConfig.java:872)
                at org.glassfish.jersey.server.ResourceConfig.getClasses(ResourceConfig.java:781)
                at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1250)
                at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1221)
                at org.glassfish.jersey.server.ResourceConfig.createRuntimeConfig(ResourceConfig.java:1218)
                at org.glassfish.jersey.server.ApplicationHandler$RuntimeConfigConfigurator.init(ApplicationHandler.java:184)
                at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$0(ApplicationHandler.java:307)
                at java.base/java.util.Arrays$ArrayList.forEach(Arrays.java:4266)
                at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:307)
                at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:274)
                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:338)
                at jakarta.servlet.GenericServlet.init(GenericServlet.java:143)
                at jakarta.servlet.http.HttpServlet.init(HttpServlet.java:121)
                at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:837)
                at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:794)
                at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:698)
                at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4172)
                at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4458)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:599)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:571)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:654)
                at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:969)
                at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
                at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1703)
                at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
                at java.base/java.lang.reflect.Method.invoke(Method.java:580)
                at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:264)
                at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:803)
                at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:802)
                at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1445)
                at org.apache.catalina.manager.HTMLManagerServlet.upload(HTMLManagerServlet.java:251)
                at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:178)
                at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590)
                at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
                at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:428)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
                at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
                at org.apache.catalina.filters.HttpHeaderSecurityFilter.doFilter(HttpHeaderSecurityFilter.java:129)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)

这是我的

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <name>My Application</name>
    <artifactId>my-application</artifactId>
    <packaging>war</packaging>
    <parent>
        <groupId>my.application.core</groupId>
        <artifactId>my-application</artifactId>
        <version>2.01</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>3.10.8</version>
            <classifier>jakarta</classifier>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-reload4j</artifactId>
            <version>2.0.13</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.mycila</groupId>
            <artifactId>license-maven-plugin</artifactId>
            <version>4.5</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.orm</groupId>
            <artifactId>hibernate-jcache</artifactId>
            <version>6.5.2.Final</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>4.0.5</version>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>4.0.2</version>
        </dependency>
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>jakarta.servlet.jsp.jstl</groupId>
            <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
            <version>3.0.0</version>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.4.0</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.7.6</version>
                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <configuration>
                            <nodeVersion>v10.15.3</nodeVersion>
                            <npmVersion>6.4.1</npmVersion>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

我的

web.xml

<web-app
        xmlns = "https://jakarta.ee/xml/ns/jakartaee"
        xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation = "https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
        version = "6.0"
>
    <display-name>Display Name</display-name>
    <description>Description</description>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:/spring-servlet.xml
            classpath:/security-app-context.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <listener>
      <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>


    <filter>
        <filter-name>cacheControlFilter</filter-name>
        <filter-class>my.application.core.CacheControlFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>cacheControlFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>JerseyContainer</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>my.application.core.my.application</param-value>
        </init-param>
        <init-param>
            <param-name>jersey.config.server.provider.classnames</param-name>
            <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>JerseyContainer</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>login.html</welcome-file>
    </welcome-file-list>

</web-app>

我很困惑正在使用什么

javax

我已将所有包和导入更新为

jakarta
,并且在我的任何包或代码中都没有提及
javax
,除了
javax.naming
javax.sql
javax.crypto
。我浏览了 IntelliJ 中的所有外部库,也找不到任何提及
javax

java spring hibernate tomcat jersey
1个回答
0
投票

我从 pom.xml 中删除了以下内容:

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>4.0.5</version>
</dependency>

我仍然不确定它是如何使用 javax 的,但我发现我不再使用它,并且应用程序现在部署时没有错误。

© www.soinside.com 2019 - 2024. All rights reserved.