简体   繁体   English

404错误:无法调用非常简单的Rest Web服务的基本方法

[英]404 error : unable to call a basic method of a very simple rest web service

I try to implement at home a simple rest web service in order to learn this technology. 我试图在家中实现一个简单的Rest Web服务,以学习该技术。

I use the latest version of JBoss EAP : the 7. I have created under Java 8 a Maven project. 我使用最新版本的JBoss EAP:7.在Java 8下创建了一个Maven项目。 The deployment is ok but when i want to call a method of my REST Web Service, i have a 404 error. 部署可以,但是当我想调用REST Web服务的方法时,出现404错误。

I follow what to do on specifications and tutorial. 我遵循有关规范和教程的内容。

1) I create a WAR whose name is bddsorties In the pom, i have : 1)我创建了一个名为bddsorties的WAR,在pom中,我有:

**<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <warName>sortiesbdd</warName>
            </configuration>
</plugin>**

2) I have a class that extends the javax.ws.rs.core.Application class : public class App extends Application. 2)我有一个扩展javax.ws.rs.core.Application的类:公共类App扩展了Application。 This class is annotated : @ApplicationPath("/messorties") 此类带有注释: @ApplicationPath(“ / messorties”)

@ApplicationPath("/messorties")
public class App extends Application
{
    public static void main( String[] args)
    {
        System.out.println( "Just the Main Class Here!" );
    }
}

3) I have another class, my Web Service annotated with @Path : @Path("accueil") 3)我还有另一个类, 我的Web服务带有@Path注释: @Path(“ accueil”)

4) In this Web Service class called HelloWorld, there is a basic method that i want to call annotated with @Path("helloworld") 4) 在这个名为HelloWorld的Web服务类中 ,有一个我想调用的带有 @Path(“ helloworld”) 注释基本方法

@Path("accueil")
public class HelloWorld {

    @GET
    @Path("helloworld")
    public Response getHelloWorld() {
        String value = "Hello World Thomas in REST World";
        return Response.status(200).entity(value).build();
    }
}

When i want to call this method by typing http://localhost:8080/sortiesbdd/messorties/accueil/helloworld , i have a 404 error : Error HTTP 404 当我想通过键入http:// localhost:8080 / sortiesbdd / messorties / accueil / helloworld来调用此方法时,出现404错误:错误HTTP 404

What is wrong in my code ? 我的代码有什么问题? i am looking for 2 days, and i can't find a solution. 我正在寻找2天,但我找不到解决方案。 For me, all seem to be ok, but, there is a mistake that i can't find. 对我来说,一切似乎都还可以,但是,有一个我找不到的错误。

Thank you in advance, Thomas 预先谢谢你,托马斯

PS: As i read on JBoss documentation, i have a web.xml file, but empty. PS:在阅读JBoss文档时,我有一个web.xml文件,但为空。

Expose your resource classes via App like below: 通过App公开您的资源类别,如下所示:

@ApplicationPath("/messorties")
public class App extends Application{

private final Set<Class<?>> classes;

public App(){

 classes = new HashSet<>();
    // add Resources
    classes.add(HelloWorld.class);
}

@Override
public Set<Class<?>> getClasses() {
    return classes;
}

}

Also declare your all @path annotations like @path("/accueil") 同时声明所有@path注释,例如@path(“ / accueil”)

尝试这样声明您的@Path批注:@Path(“ / accueil”)和@Path(“ / helloworld”)

leave the war file name from the path: http://localhost:8080/messorties/accueil/helloworld 从以下路径保留战争文件名: http:// localhost:8080 / messorties / accueil / helloworld

edit #1: 编辑#1:

I just checked one of my projects I deploy on Wildfly: do you have a webapp/WEB-INF/jboss-web.xml file? 我刚刚检查了我在Wildfly上部署的项目之一:您是否有一个webapp / WEB-INF / jboss-web.xml文件?

I have the context root defined there: 我在那里定义了上下文根:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="8.0" xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/schema/jbossas/jboss-web_8_0.xsd">
  <context-root>/sortiebdd</context-root>
</jboss-web>

check if you have this configuration defining the context root. 检查您是否具有定义上下文根的此配置。

edit #2: 编辑#2:

besides the jboss-web.xml I have a beans.xml in the WEB-INF directory with this content: 除了jboss-web.xml,我在WEB-INF目录中还有一个bean.xml,其内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<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="annotated">
</beans>

I have no web.xml, because with the beans.xml and the bean-discovery-mode set to annotated, the web.xml is not needed anymore. 我没有web.xml,因为将bean.xml和bean-discovery-mode设置为带注释的,就不再需要web.xml。

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

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