JBossWS中的Spring配置

JBossWS中的Spring配置,spring,jboss,jakarta-ee,jbossws,Spring,Jboss,Jakarta Ee,Jbossws,我试图使用JBossWS(本机堆栈)公开一个web服务,并利用Spring的依赖注入。以下是我的代码的简化版本: web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="htt

我试图使用JBossWS(本机堆栈)公开一个web服务,并利用Spring的依赖注入。以下是我的代码的简化版本:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
     version="2.4">

    <display-name>Test Service</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>

    <listener> 
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <servlet>    
        <servlet-name>EndpointService</servlet-name>
        <servlet-class>com.blah.webservice.EndpointService</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>EndpointService</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation=" http://www.springframework.org/schema/beans
                             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                             http://www.springframework.org/schema/context
                             http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:spring-configured />
    <context:load-time-weaver />
    <context:annotation-config />

    <context:component-scan base-package="com.blah.webservice" />
</beans>
package com.blah.webservice;

import org.springframework.stereotype.Service; 

@Service
public class TestService {

    public TestService() {}

    public String serviceEcho(String echo) {
        return echo;
    }
}
TestService.java:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
     version="2.4">

    <display-name>Test Service</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>

    <listener> 
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <servlet>    
        <servlet-name>EndpointService</servlet-name>
        <servlet-class>com.blah.webservice.EndpointService</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>EndpointService</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation=" http://www.springframework.org/schema/beans
                             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                             http://www.springframework.org/schema/context
                             http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:spring-configured />
    <context:load-time-weaver />
    <context:annotation-config />

    <context:component-scan base-package="com.blah.webservice" />
</beans>
package com.blah.webservice;

import org.springframework.stereotype.Service; 

@Service
public class TestService {

    public TestService() {}

    public String serviceEcho(String echo) {
        return echo;
    }
}

当我构建它并部署到JBoss时,它启动得很好,我可以看到Spring正在预实例化我的类,但是当我调用web服务时,endpointEcho按预期工作,而serviceEcho抛出NullPointerException。当JBossWS实例化端点类时,它似乎没有发现我的Spring配置。有没有一种简单的方法可以告诉JBossWS关于Spring的信息?我觉得我要么错过了一些非常小的细节,要么我处理这一切都错了。有什么想法吗?

您的服务必须扩展SpringBeanAutowiringSupport,才能利用自动布线支持。

我试过了。试图调用testService仍然会给我一个NullPointerException。看起来自动布线正在进行,但可能是在错误的环境中。所以我再次尝试(第三次是一种魅力,对吗?),它似乎正在工作。我将@Autowired注释从端点类的构造函数移到了各个属性声明中,现在我正在摇摆不定。谢谢