在 GlassFish 上创建和 运行 RESTful Web 服务
Creating and Running RESTful Web Service on GlassFish
我在 GlassFish 服务器上创建了一个简单的 RESTful Web 服务,并根据 IntelliJ IDE 中的 tutorial 运行 它。根据提供的说明,这 运行 没问题。我还有 2 个问题,
一个。本教程使用下面提供的服务 class,
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
之后,我在同一目录中添加了一个新的class,
@Path("/")
public class App {
@GET
@Produces("text/plain")
public String getMessage() {
return "Hello, Berlin";
}
}
我希望从打开 URL http://localhost:8080/AppointmentManager_war_exploded/
开始在浏览器中看到消息 "Hello, Berlin"
,但是,相反,我得到了提供的错误
HTTP Status 404 - Not Found
type Status report
messageNot Found
descriptionThe requested resource is not available.
GlassFish Server Open Source Edition 5.0
这里有什么问题?
b。如何将 URL AppointmentManager_war_exploded
的部分更改为其他内容,例如 appointment
等?下面提供了项目设置中的 artifact
选项卡,
我编辑了它,但是,它的变化并不符合预期。
我在教程之后将项目更改为 maven
build,但是,问题不是为此创建的。如果有人感兴趣,你也可以试试,因为 运行 需要一分钟。
谢谢。
第一
I expected to see the message "Hello, Berlin" in the browser from the opening URL http://localhost:8080/AppointmentManager_war_exploded/, but, instead, I get the error provided
在教程提供的 MyApplication
class 中,您还应该添加新的 class:
@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/
上看到预期的页面
第二
How do I change the part of URL AppointmentManager_war_exploded to something else, say, appointment etc?
URL 包含您的神器名称 AppointmentManager_war_exploded
。此工件自动复制到 glassfish 应用程序目录。您可以检查glassfish\domains\domain1\applications\__internal
。
只需在项目结构 window 中更改它即可:
更新
不要忘记在应用的配置设置中更改开始 URL:
我在 GlassFish 服务器上创建了一个简单的 RESTful Web 服务,并根据 IntelliJ IDE 中的 tutorial 运行 它。根据提供的说明,这 运行 没问题。我还有 2 个问题,
一个。本教程使用下面提供的服务 class,
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
之后,我在同一目录中添加了一个新的class,
@Path("/")
public class App {
@GET
@Produces("text/plain")
public String getMessage() {
return "Hello, Berlin";
}
}
我希望从打开 URL http://localhost:8080/AppointmentManager_war_exploded/
开始在浏览器中看到消息 "Hello, Berlin"
,但是,相反,我得到了提供的错误
HTTP Status 404 - Not Found
type Status report
messageNot Found
descriptionThe requested resource is not available.
GlassFish Server Open Source Edition 5.0
这里有什么问题?
b。如何将 URL AppointmentManager_war_exploded
的部分更改为其他内容,例如 appointment
等?下面提供了项目设置中的 artifact
选项卡,
我编辑了它,但是,它的变化并不符合预期。
我在教程之后将项目更改为 maven
build,但是,问题不是为此创建的。如果有人感兴趣,你也可以试试,因为 运行 需要一分钟。
谢谢。
第一
I expected to see the message "Hello, Berlin" in the browser from the opening URL http://localhost:8080/AppointmentManager_war_exploded/, but, instead, I get the error provided
在教程提供的 MyApplication
class 中,您还应该添加新的 class:
@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/
第二
How do I change the part of URL AppointmentManager_war_exploded to something else, say, appointment etc?
URL 包含您的神器名称 AppointmentManager_war_exploded
。此工件自动复制到 glassfish 应用程序目录。您可以检查glassfish\domains\domain1\applications\__internal
。
只需在项目结构 window 中更改它即可:
更新
不要忘记在应用的配置设置中更改开始 URL: