繁体   English   中英

Wildfly 11,具有resteasy抛出404,未找到端点

[英]Wildfly 11 with resteasy throwing 404 and no endpoints found

我有一个使用maven,resteasy-3.0.24.Final,wildfly 11开发的项目。

当我尝试使用邮递员访问端点之一时,出现404错误。

<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-我认为没有必要使用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;
    }
  }

资源

@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) {}

我尝试访问http:// localhost:8080 / Library-management / rest / bookResource / addBook,但是没有运气。 而且,在“独立服务器监视器:子系统子系统:Web服务”中没有定义任何端点。

任何帮助将不胜感激。 提前致谢。

注意:我能够在tomcat中部署此项目,并且工作正常。

知道了。

Wildfly-11轻松自在

依赖-

<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>

应用-

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

资源-

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\":\"";
    }
}

网址: http:// localhost:8080 / {context} / rest / get

注意:从wildfly-10开始,不需要Web xml。

暂无
暂无

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

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