Soap 获取对wildfly上WebServletContext的引用

Soap 获取对wildfly上WebServletContext的引用,soap,jax-ws,cdi,wildfly,jboss-weld,Soap,Jax Ws,Cdi,Wildfly,Jboss Weld,我正在尝试在wildfly 9.0.1-Final上部署soap Web服务。我试图通过资源注入来访问WebServletContext,但它总是空的。我在WEB-INF中有一个beans.xml文件。下面是类定义 loadProperties是从contstructor调用的 @WebService(endpointInterface = "com.ticomgeo.interfaces._2010.geonet.healthandstatus.v2.HealthAndStatusPortT

我正在尝试在wildfly 9.0.1-Final上部署soap Web服务。我试图通过资源注入来访问WebServletContext,但它总是空的。我在WEB-INF中有一个beans.xml文件。下面是类定义

loadProperties是从contstructor调用的

@WebService(endpointInterface =  "com.ticomgeo.interfaces._2010.geonet.healthandstatus.v2.HealthAndStatusPortType", 
portName = "HealthAndStatusPort", 
wsdlLocation = "WEB-INF/classes/HealthAndStatusServiceV2.wsdl", serviceName = "HealthAndStatusService", 
targetNamespace = "http://interfaces.ticomgeo.com/2010/geonet/HealthAndStatus/v2")
@HandlerChain(file="/HandlerChain.xml")
@XmlSeeAlso({
    com.ticomgeo.schemas._2010.geonet.classificationtypes.v0.ObjectFactory.class,
    com.ticomgeo.schemas._2010.geonet.designatortypes.v0.ObjectFactory.class,
    com.ticomgeo.schemas._2010.geonet.basictypes.v0.ObjectFactory.class,
    com.ticomgeo.schemas._2010.geonet.healthandstatusspecialtypes.v2.ObjectFactory.class,
    com.ticomgeo.schemas._2010.geonet.platformandsystemtypes.v2.ObjectFactory.class,
    com.ticomgeo.schemas._2010.geonet.common.signaltypes.v0.ObjectFactory.class,
    com.ticomgeo.schemas._2010.geonet.platformantennatypes.v0.ObjectFactory.class,
    com.ticomgeo.schemas._2010.geonet.platformandsystemresourcetypes.v0.ObjectFactory.class,
    com.ticomgeo.schemas._2010.geonet.common.servicemessagetypes.v0.ObjectFactory.class,
    com.ticomgeo.schemas._2010.geonet.healthandstatusspecialgeoservicetypes.v2.ObjectFactory.class })
public class HealthAndStatusPortImpl extends EimWebService implements HealthAndStatusPortType {

private final static Logger log = Logger.getLogger(new Exception().getStackTrace()[0]
        .getClassName());
private final static Logger LOGGER=log;
private HSProperties props;
private ServiceState serviceState;
private AggregatorConnectionThread aggregatorConnectionThread;
public  String configHome=null;

  @Resource(name="wscontext")
private WebServiceContext wscontext;

public void loadProperties() {
    if (wscontext==null){
         throw new RuntimeException("wscontext = "+wscontext);
    }
部署总是失败,WebServletContext上的null测试出现异常

[standalone@localhost:9990 /] deploy /tmp/HealthAndStatusServiceV2.war
{"WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"HealthAndStatusServiceV2.war\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"HealthAndStatusServiceV2.war\".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment \"HealthAndStatusServiceV2.war\"
    Caused by: java.lang.RuntimeException: java.lang.RuntimeException: wscontext = null
    Caused by: java.lang.RuntimeException: wscontext = null"},"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"HealthAndStatusServiceV2.war\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"HealthAndStatusServiceV2.war\".beanmanager]","jboss.deployment.unit.\"HealthAndStatusServiceV2.war\".batch.environment is missing [jboss.deployment.unit.\"HealthAndStatusServiceV2.war\".beanmanager]"]}}}
[standalone@localhost:9990 /] 
提前感谢您的帮助

更新:

将资源批注更改为

@Resource
private WebServiceContext wscontext;

但是在部署时得到了相同的结果如果指定@Resource name属性(wscontext),那么应该在部署描述符(web.xml env entry元素)中正确描述它。否则,您可以让应用服务器生成的所有JNDI内容完全不指定name属性。

将资源注释更改为@resource private WebServiceContext wscontext,但在部署时得到相同的结果。看起来您的组件是用CDI实例化的,但@resource不是CDI的一部分。您真的需要构造函数中的WebServiceContext吗?我怀疑CDI实例化了您的组件,然后将@Resource委托给app server来完成注入。在您的情况下,如果您立即使用@Resource,它可能尚未正确初始化。我需要在构造函数中使用它来获取servlet上下文。我曾经能够使用servletContextListener来处理这个问题,它一直工作到Tomcat7.0.25,包括它。如果我们尝试在7.0.39上部署,则在ws-impl构造之前不会调用contextListener。由于我们正在切换到wildfly,并且有一种从WebServletContext获取servlet上下文的方法,因此它似乎是一个很好的选择。然而,我对注释还是很陌生。是否有其他注释可用于强制注入WebServletContext?@Inject会这样做吗?在这种情况下,我将创建一个带@Inject注释的构造函数,并将ServletContext作为参数