Java 在EAR中打包时Webservice不可用

Java 在EAR中打包时Webservice不可用,java,web-services,jboss7.x,Java,Web Services,Jboss7.x,我们有一个Web服务,它包含在ear中的ejb jar中。然后将该jar部署到JBoss 7.2.0.Final实例 据了解,在会话bean上使用webservice注释应该足够了 因此,Web服务如下所示: @WebService(name = "TestWS", targetNamespace="http://test.com/ws") @WebContext(contextRoot="/test-ws", urlPattern="/*", transportGuarantee="NONE"

我们有一个Web服务,它包含在ear中的ejb jar中。然后将该jar部署到JBoss 7.2.0.Final实例

据了解,在会话bean上使用webservice注释应该足够了

因此,Web服务如下所示:

@WebService(name = "TestWS", targetNamespace="http://test.com/ws")
@WebContext(contextRoot="/test-ws", urlPattern="/*", transportGuarantee="NONE", secureWSDLAccess=false)
@Stateless  
public class TestWS
{
  @WebMethod
  public String sayHello()
  {
    return "hello";
  }
}
耳朵展开后,一切正常。问题是,在部署打包的ear(.ear文件)时,服务似乎不可用

管理控制台在两种情况下都显示此信息:

Context: test-ws
Type: JAXWS_EJB3
WSDL Url: http://localhost:8080/test-ws?wsdl
 [org.jboss.ws.cxf.metadata] (MSC service thread 1-4) JBWS024061: Adding service  
   endpoint metadata: id=TestWS
   address=http://localhost:8080/test-ws
   implementor=com.test.TestWS
   serviceName={http://test.com/ws}TestWSService
   portName={http://test.com/ws}TestWSPort
   annotationWsdlLocation=null
   wsdlLocationOverride=null    
   mtomEnabled=false
 ...
[org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-9) Setting the server's publish address to be http://localhost:8080/test-ws
在启动过程中,两种情况下都会记录以下内容:

Context: test-ws
Type: JAXWS_EJB3
WSDL Url: http://localhost:8080/test-ws?wsdl
 [org.jboss.ws.cxf.metadata] (MSC service thread 1-4) JBWS024061: Adding service  
   endpoint metadata: id=TestWS
   address=http://localhost:8080/test-ws
   implementor=com.test.TestWS
   serviceName={http://test.com/ws}TestWSService
   portName={http://test.com/ws}TestWSPort
   annotationWsdlLocation=null
   wsdlLocationOverride=null    
   mtomEnabled=false
 ...
[org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-9) Setting the server's publish address to be http://localhost:8080/test-ws
当耳朵被炸开时
http://localhost:8080/test-ws?wsdl
检索wsdl,当ear被打包时,我得到以下结果:

JBWEB000065: HTTP Status 404 - /test-ws
JBWEB000309: type JBWEB000067: Status report
JBWEB000068: message /test-ws
JBWEB000069: description JBWEB000124: The requested resource is not available.

有什么想法可能遗漏了什么吗?

我在许多项目中也遇到过这种情况。以下任何一种方法都可能有效:)

1.)在EAR中打包一个WAR,并拥有web.xml,这将为您的web服务提供一个良好的开端

2.)尝试在
META-INF/application.xml
中加载jar,它将完美地包含您的jar文件

application.xml将如下所示

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
  <display-name>project-name</display-name>
  <module>
    <java>your_jar_file_name</java>
  </module>
</application>

项目名称
您的\u jar\u文件\u名称

它与Endpoint#publish一起工作吗?@PhilippSander不是为非AS使用而设计的
Endpoint#publish
?你的意思是我应该在启动期间从另一个服务调用它吗?是的。但是它能工作吗?这个错误不是简单地告诉您,当应用程序打包为ear时,应用程序的上下文名称不是您所期望的(/test ws)?@PhilippSander我添加了
Endpoint.publish(“http://:8080/test ws”,new TestWS())在启动时发送到服务,我仍然会收到相同的错误。感谢您的建议。如果没有其他选择,我会考虑使用方法1。方法2不起作用,因为jar模块已经存在于application.xml中。因此,解决问题的方法也解决了问题(解决方案接近您的方法1:)