Does JAX-RS needs an web-module WAR
or am i doing something wrong?
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?
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
Project structure
- ear
- EjbModule.jar
Code
Exposing a Bean as a JAX-WS web service and testing it in browser is no problem.
@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();
}
}
Environment: Glassfish 4.0
Edit:
Creating a separate WAR
the rest service works as expected.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…