NameAlreadyBoundException 如果在具有 web.xml 的 Web 服务中使用 @Stateless

NameAlreadyBoundException if use of @Stateless in a webservice with web.xml

我正在尝试使用以下注释在 Weblogic 12c 中部署 Web 服务:

@SchemaValidation
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
@WebService(serviceName = "xxxxx",
        targetNamespace = "http://bla/BusinessServices/yyy/xxxxx/V1",
        wsdlLocation = "META-INF/wsdl/zzz/yyy/xxxxx/V1/xxxxxConcrete.wsdl",
        portName = "xxxxxPort",
        endpointInterface = "ble.businessservices.yyy.xxxxx.v1.xxxxx")
//@Transactional(value= Transactional.TransactionFlowType.SUPPORTS, version= Transactional.Version.WSAT12)
@Stateless
@SecurityPolicies(@SecurityPolicy(uri = "my_policy"))
@DeclareRoles("my-role")
@Interceptors({InterceptorClass1.class, InterceptorClass2.class, InterceptorClass3.class})
public class xxxxxV1 extends HttpServlet implements xxxxx {...}

我正在使用 web.xml 来定义 servlet 别名,并使用 weblogic.xml 文件来定义我要使用的上下文根。

问题是,如果我保留@Stateless 注释,在部署时会出现以下异常:

Target state: deploy failed on Server services_server
javax.naming.NameAlreadyBoundException: my-webservice-name-impl-1.0.0.0-SNAPSHOT.war#MyWebServiceName is already bound; remaining name 'app/wsee'
    at weblogic.deploy.api.tools.deployer.Jsr88Operation.report(Jsr88Operation.java:547)
    at weblogic.deploy.api.tools.deployer.Deployer.perform(Deployer.java:140)
    at weblogic.deploy.api.tools.deployer.Deployer.runBody(Deployer.java:88)
    at weblogic.utils.compiler.Tool.run(Tool.java:158)
    at weblogic.utils.compiler.Tool.run(Tool.java:115)
    at weblogic.Deployer.run(Deployer.java:74)
    ... 15 more

另一方面,如果我删除 web.xml,我可以毫无错误地部署,但是我的 web 服务的 URL 当然不是我想要定义的:它使用 / portName/serviceName URL.

而且,如果我删除 @Stateless 注释,我得到了所需的 URL,但是 拦截器被忽略了,这在逻辑上是不可接受的。

我已经尝试使用 @Transactional 注释(参见上面的注释代码),但是拦截器总是被忽略。

有人知道我错过了什么吗?理想情况下,我会使用 web.xml 和 @Transactional 并进入拦截器。

谢谢大家!

找到了使一切按需工作的解决方法:the delegation pattern

Web 服务 class 现在具有以下注释:

@SchemaValidation
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
@WebService(serviceName = "xxxxx",
        targetNamespace = "http://bla/BusinessServices/yyy/xxxxx/V1",
        wsdlLocation = "META-INF/wsdl/zzz/yyy/xxxxx/V1/xxxxxConcrete.wsdl",
        portName = "xxxxxPort",
        endpointInterface = "ble.businessservices.yyy.xxxxx.v1.xxxxx")
@Transactional(value= Transactional.TransactionFlowType.SUPPORTS, version= Transactional.Version.WSAT12)
@SecurityPolicies(@SecurityPolicy(uri = "my_policy"))
public class xxxxxV1 extends HttpServlet implements xxxxx {...}

然后我使用带有以下注释的委托 class xxxxxV1Delegate

@Stateless
@DeclareRoles("my-role")
@Interceptors({InterceptorClass1.class, InterceptorClass2.class, InterceptorClass3.class})
public class xxxxxV1Delegate {...}

在此 class 中完成所有实施(基本上是复制粘贴网络服务 class 中的内容并删除 @Overrides)

Web 服务 class 将注入 xxxxxV1Delegate 并包含所有 @Override 方法。每个方法只会调用委托中完全相同的方法 class.