创建和GlassFish上运行RESTful Web服务

问题描述 投票:2回答:1

我创建了GlassFish服务器上的一个简单的RESTful Web服务,并根据该tutorial在的IntelliJ IDE运行它。这种运行良好基础上提供的说明。我有2个额外的问题,

一种。本教程采用的是服务类下面提供,

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/helloworld")
public class HelloWorld {

    @GET
    @Produces("text/plain")
    public String getClichedMessage() {

        return "Hello World";
    }
}

我可以访问从所提供的URL

http://localhost:8080/AppointmentManager_war_exploded/helloworld

后来,我在同一个目录中添加一个新的类,

@Path("/")
public class App {

    @GET
    @Produces("text/plain")
    public String getMessage() {

        return "Hello, Berlin";
    }
}

我期望看到的消息"Hello, Berlin"从开口URL http://localhost:8080/AppointmentManager_war_exploded/的浏览器,但是,相反,我得到提供的错误,

HTTP Status 404 - Not Found
type Status report

messageNot Found

descriptionThe requested resource is not available.

GlassFish Server Open Source Edition 5.0

什么是这里的问题?

湾如何URL AppointmentManager_war_exploded的部分更改为别的东西,比如说,appointment等?在项目设置的artifact选项卡下方,

enter image description here

我编辑它,但是,按预期的方式不对应的变化。

我改变了项目的教程后maven构建,但是,没有为创建该问题。如果有人有兴趣,你可以尝试过,因为它会花一分钟来运行。

谢谢。

java rest maven jersey jax-rs
1个回答
1
投票

第一

我期望看到消息“Hello,柏林”从开幕URL http://localhost:8080/AppointmentManager_war_exploded/的浏览器,但是,相反,我得到提供的错误

在通过教程提供MyApplication类,你还应该添加新类:

@ApplicationPath("/")
public class MyApplication extends Application{
    @Override
    public Set<Class<?>> getClasses() {
        HashSet h = new HashSet<Class<?>>();
        h.add(HelloWorld.class);
        h.add(App.class);          // Add your new class here
        return h;
    }
}

然后,你就可以看到http://localhost:8080/AppointmentManager_war_exploded/预期的页

第二

如何URL AppointmentManager_war_exploded的部分更改为别的东西,比如说,任用等?

URL包含您的神器AppointmentManager_war_exploded的名称。这神器自动复制到GlassFish应用程序目录。您可以检查glassfish\domains\domain1\applications\__internal。只要改变它只是在这里的项目结构窗口:

enter image description here

更新

不要忘记更改起始URL的配置设置的应用程序:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.