首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >JBossWS中的弹簧配置

JBossWS中的弹簧配置
EN

Stack Overflow用户
提问于 2011-03-14 20:28:04
回答 1查看 1.3K关注 0票数 3

我试图使用JBossWS (本机堆栈)公开web服务,并利用Spring的依赖项注入。下面是我的代码的一个经过擦洗的版本:

web.xml:

代码语言:javascript
运行
复制
<?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>

applicationContext.xml:

代码语言:javascript
运行
复制
<?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>

EndpointService.java

代码语言:javascript
运行
复制
package com.blah.webservice;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 

@Service
@WebService
@SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.BARE)
public class EndpointService {

    private TestService testService;

    public EndpointService() {}

    @Autowired
    public EndpointService(TestService testService) {
        this.testService = testService;        
    }

    @WebMethod
    public String endpointEcho(String echo) {
        return echo;
    }

    @WebMethod
    public String serviceEcho(String echo) {
        return testService.serviceEcho(echo);
    }
}

TestService.java:

代码语言:javascript
运行
复制
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的事吗?我觉得我要么错过了一些很小的细节,要么我把这一切都搞错了。有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-16 09:57:17

您的服务必须扩展SpringBeanAutowiringSupport,以便能够利用自动支持。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5304102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档