简体   繁体   中英

Wildfly 11 with resteasy throwing 404 and no endpoints found

I have a project developed using maven, resteasy-3.0.24.Final, wildfly 11.

When I tried to access one of the end point using postman, I got a 404 error.

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-servlet-initializer</artifactId>
    <version>3.0.24.Final</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.0.24.Final</version>
</dependency>

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>3.0.24.Final</version>
</dependency>

web.xml - I think it is not necessary for wildfly11

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>Library</display-name>
   <display-name>Library</display-name>

   <context-param>
      <param-name>resteasy.servlet.mapping.prefix</param-name>
      <param-value>/rest</param-value>
   </context-param>

</web-app>

def-

@ApplicationPath("/rest")
    public class LibraryApplication extends Application {

    private Set<Object> singletons = new HashSet<Object>();

    public LibraryApplication() {
        singletons.add(new BookResource());
    }

    @Override
    public Set<Object> getSingletons() {
        return singletons;
    }
  }

resource

@Path("/bookResource")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public class BookResource {
@Inject
private LibrarianEntityManager manager;

@Path("/addBook")
@POST
public Response addBook(BookModel bookModel) {}

I tried to access http://localhost:8080/Library-management/rest/bookResource/addBook but no luck. And none of the endpoints defined in Standalone Server Monitor: Subsystems Subsystem: Web Services.

Any help would be highly appreciated. Thanks in advance.

Note: I was able to deploy this project in tomcat and it did working fine.

Got it worked.

Wildfly-11 with rest-easy

Dependency -

<dependency>
    <groupId>org.jboss.spec.javax.annotation</groupId>
    <artifactId>jboss-annotations-api_1.2_spec</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.jboss.spec.javax.ws.rs</groupId>
    <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
    <scope>provided</scope>
</dependency>

beans.xml-

<?xml version="1.0" encoding="UTF-8"?>
<!-- Marker file indicating CDI should be enabled -->
<beans 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/beans_1_1.xsd"
    bean-discovery-mode="all">
</beans>

index.xml-

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Library-management</title>
</head>
<body>

    <p>hello world</em>:

    <ul>
        <li><a href="rest/">abc</a></li>
    </ul>
</body>
</html>

Application-

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("rest")
public class LibraryApplication extends Application {
}

Resource-

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@Path("/")
public class BookResource {
    @GET
    @Path("/get")
    @Produces({ "application/json" })
    public String getHelloWorld() {
        return "{\"result\":\"";
    }
}

URL: http://localhost:8080/ {context}/rest/get

Note: Web xml is not required from wildfly-10 onwards.

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