Exposing EJB method as REST service

孤者浪人 提交于 2019-12-21 04:55:08

问题


In J2EE 6 you can expose your EJB session bean as a REST web service as below

@Stateless
@Path("/test")
public class TestSessionBean {
  @GET
  @Produces("application/xml")
  public String getTest() {
    return "<?xml version='1.0' encoding='UTF-8'?><val>test session bean</val>";
  }
}

This works when I packaged the EJB in the .war, however, when I try to package my project into separate web and ejb modules inside an EAR I get an HTML 404 not found error.

Can someone please explain?

I'm using Glassfish v3

Here is my web.xml

<servlet>
    <servlet-name>TaskRestService</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
  <load-on-startup>1</load-on-startup>


</servlet>
<servlet-mapping>
  <servlet-name>TaskRestService</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

回答1:


JAX-RS annotated enterprise beans in a stand-alone or in a separate ejb-jar file that is included in an EAR is not supported.

See below

http://pic.dhe.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=%2Fcom.ibm.websphere.nd.iseries.doc%2Finfo%2Fiseriesnd%2Fae%2Ftwbs_jaxrs_ejb_localinterface.html



来源:https://stackoverflow.com/questions/4372361/exposing-ejb-method-as-rest-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!