简体   繁体   中英

JAX-RS resources return 404

I am trying to run a simple app in Jakarta 9 that has a simple REST web service that returns hello world. However, when I try to access the web service using the localhost:8080/<context_root>/<application_path>/<resource_path I get 404. When I just target localhost:8080/<context_root> everything runs fine (I have an index.html in the project).

Here is some additional info. I am running the app packaged as a WAR inside Wildfly 25 running inside the Docker container.

Here's the relevant file content

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>
  <groupId>com.tyuiop32</groupId>
  <artifactId>TimeTracking</artifactId>
  <version>1.0</version>
  <packaging>war</packaging>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
  </properties>
  <dependencies>

    <dependency>
      <groupId>jakarta.platform</groupId>
      <artifactId>jakarta.jakartaee-web-api</artifactId>
      <version>9.0.0</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>com.auth0</groupId>
      <artifactId>java-jwt</artifactId>
      <version>3.8.3</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-jpa</artifactId>
      <version>1.11.23.RELEASE</version>
    </dependency>

  </dependencies>
  <build>
    <finalName>TimeTracking</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.10.1</version>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.3.2</version>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

ApplicationConfig.java:

package com.poortoys;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

/**
 * Register Jakarta REST resources.
 *
 */
@ApplicationPath("")
public class ApplicationConfig extends Application {

}

HelloResource.java:

package com.poortoys.examples;

import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

/**
 * Sample JAX-RS resources.
 *
 */
@Path("test")
@RequestScoped
public class HelloResource {
    
    @GET
    @Path("hello")
    @Produces(MediaType.APPLICATION_JSON)
    public String getMessage() {
        return "Hello, world";
    }
    
}

When I try to GET http://localhost:8080/TimeTracking/test/hello I get 404

Targeting just http://localhost:8080/TimeTracking returns the content of the index.html page that is placed inside the webapp folder

PS: I went trough all the relevant threads and didn't find the asnwer

You'd need to use WildFly 27. WildFly 25 is a Jakarta EE 8 container while WildFly 27 is a Jakarta EE 10 container. You could use WildFly 25 Preview, but I would suggest using WildFly 27.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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