JAX-RS需要一个战争模块吗? [英] Does JAX-RS needs a war module?
问题描述
JAX-RS需要一个网络模块 WAR
或者我做错了吗?
Does JAX-RS needs an web-module WAR
or am i doing something wrong?
每个教程指定在 web.xml
中配置休息服务。
但是在ejb模块中没有 web.xml
。我必须为其余的服务创建一个 WAR
Every tutorial states to config the rest-service in web.xml
.
But in ejb-module there is no web.xml
. Must I create a WAR
just for the rest service?
在我的ejb模块中,我想公开一个EJB休息服务,但不能让它上班。
调用localhost:8080 / EjbModule / rest / test / method导致404
In my ejb module I want to expose a EJB as a rest service but cannot get it to work. Calling "localhost:8080/EjbModule/rest/test/method" leads to 404
项目结构
- ear
- EjbModule.jar
代码
将Bean暴露为JAX-WS Web服务并在浏览器中进行测试没有问题。
@ApplicationPath("rest")
public class RestApplication extends Application
{
@Override
public Set<Class<?>> getClasses()
{
final Set<Class<?>> classes = new HashSet<>(1);
classes.add(TestService.class);
return classes;
}
}
@Stateless
@Path("/test")
public class TestService
{
@Path("/method")
@GET
@Produces(MediaType.TEXT_HTML)
public String test()
{
return new Date().toString();
}
}
环境:Glassfish 4.0
Environment: Glassfish 4.0
编辑:
创建一个单独的 WAR
推荐答案
从 JAX-RS Specification 2.0 p。 8:
2.3.2 Servlet
JAX-RS应用程序已打包作为一个ww文件中的Web应用程序。应用程序类包装在WEB-INF / classes或
WEB-INF / lib中,所需的库打包在WEB-INF / lib中。有关包装web
应用程序的详细信息,请参阅
Servlet规范。
2.3.2 Servlet
A JAX-RS application is packaged as a Web application in a .war file. The application classes are packaged in WEB-INF/classes or WEB-INF/lib and required libraries are packaged in WEB-INF/lib. See the Servlet specification for full details on packaging of web applications.
这是标准方式if您希望在Web容器中部署您的JAX-RS应用程序。然而,规范还指出,应用程序可以运行在不同的容器中,如ejb容器甚至Java SE环境。但是对于其他容器,没有任何指定:
This is the standard way if you want to deploy your JAX-RS application in a web-container. However the specification points also out that applications can run in different containers like ejb-containers or even an Java SE environment. But for other containers there is nothing specified:
实现可以提供在其他类型的容器中托管JAX-RS应用程序的功能,例如设施超出了本规范的范围。
An implementation MAY provide facilities to host a JAX-RS application in other types of container, such facilities are outside the scope of this specification.
这篇关于JAX-RS需要一个战争模块吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!