简体   繁体   English

从 Tomcat7 / Jersey 2.25 / Servlet 2.5 升级到 Tomcat 10 / Jersey 3.0.8 / Servlet 时出现 404 错误

[英]404 error when upgrading from Tomcat7 / Jersey 2.25 / Servlet 2.5 to Tomcat 10 / Jersey 3.0.8 / Servlet 5

I have a Jersey application running on Tomcat that we've had up for several years.我有一个 Jersey 应用程序在我们已经使用了几年的 Tomcat 上运行。 We are currently upgrading to Java 11 and Tomcat 10, which necessitates Servlet 5.0 and Jersey 3.0.8我们目前正在升级到 Java 11 和 Tomcat 10,这需要 Servlet 5.0 和 Jersey 3.08。

After satisfying all of the compile needs, and any runtime errors of "class not found", I am running into a problem I have been bashing my head against all day.在满足所有编译需求以及“找不到类”的任何运行时错误之后,我遇到了一个我整天都在努力解决的问题。 No matter what I try, I keep getting a 404 error.无论我尝试什么,我都会不断收到 404 错误。

I tried changing the original application from ResourceConfig:我尝试从 ResourceConfig 更改原始应用程序:

public class AppConfig extends ResourceConfig {

    public AppConfig() {
        packages("com.carpart.webservices.rest.oauth");
        property(JspMvcFeature.TEMPLATE_BASE_PATH, "/");
        register(JspMvcFeature.class);
    }
}

to a subclass of application, overriding getClasses:到应用程序的子类,覆盖 getClasses:

    public class AppConfig extends Application {
        
        @Override
        public Set<Class<?>> getClasses() {
            Set<Class<?>> s = new HashSet<Class<?>>();
            s.add( Connect.class );
            return s;
        }
        
    }

I've tried different web.xml variations from the original filter to the wording on the Jersey documentation:我尝试了不同的 web.xml 变体,从原始过滤器到 Jersey 文档中的措辞:

Original:原来的:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 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">

<filter>
    <filter-name>Jersey</filter-name>
    <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.carpart.webservices.rest.oauth.AppConfig</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <url-pattern>/*</url-pattern>
    <filter-name>Jersey</filter-name>
  </filter-mapping>
</web-app>

New:新的:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="5.0"
    xmlns="https://jakarta.ee/xml/ns/jakartaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  
    <servlet>
        <servlet-name>com.carpart.webservices.rest.oauth.AppConfig</servlet-name>
    </servlet>
     
    <servlet-mapping>
        <servlet-name>com.carpart.webservices.rest.oauth.AppConfig</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
 
 </web-app>

I've tried setting an @ApplicationPath on the application to various values from "/" to "/*" to "/api" just to see if I could get some different reaction.我尝试将应用程序上的@ApplicationPath 设置为从“/”到“/*”到“/api”的各种值,只是为了看看我是否能得到一些不同的反应。

The Connect class is defined as such: Connect class 定义如下:

@Path("/connect")
public class Connect {

    @GET
    @Path("/authorize")
    @Produces(MediaType.TEXT_HTML)
    public Response authorize(@QueryParam("client_id") String client_app_id ) {
        log.debug("Inside authorize (phase 1) GET method...");
    }
}

The Connect resource class hasn't changed.连接资源 class 未更改。 from what we had.从我们所拥有的。

I've read the Jersey 3.0.8 documentation several times with regards to configuring and deploying, but I am not seeing what is wrong.关于配置和部署,我已经多次阅读 Jersey 3.0.8 文档,但我没有看到有什么问题。

<init-param>
    <param-name>javax.ws.rs.Application</param-name>
    <param-value>com.carpart.webservices.rest.oauth.AppConfig</param-value>
</init-param>

If you're using Jersey 3, then javax needs to be changed to jakarta .如果您使用的是 Jersey 3,则需要将javax更改为jakarta No more Javax anywhere.任何地方都不再有 Javax。

Ok, So I found the issue, (Thank you Paul, your comment below the code helped trigger my thoughts this morning!)好的,所以我发现了问题,(谢谢 Paul,您在代码下方的评论帮助触发了我今天早上的想法!)

I was still including the javax.* pathed classes in my Connect class for the annotations.我仍然在我的 Connect class 中包含 javax.* 路径类作为注释。 I deleted them and re imported them all as jakarta.ws.rs.* and it recognized the Connect class as a resource.我删除了它们并将它们全部重新导入为 jakarta.ws.rs.* 并且它将 Connect class 识别为资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM