2

我们的项目使用 Spring 3.0.5 在 JBoss 6 上运行。在我们尝试使用 JAX-WS 实现一些 Web 服务之前,一切都很顺利。如果我尝试做一些简单的 WS(比如添加 2 个数字),它就可以工作 - 我放置注释并将带注释的类添加为 servlet。但是,如果我尝试让我的 JAX-WS 类填充依赖项,事情会变得越来越困难。

这是我的代码:

@WebService(name = "principal")
public class PrincipalWebService extends SpringBeanAutowiringSupport {

    @Autowired
    private PrincipalManager manager;

    @WebMethod
    public int add(int a, int b) {
        return a + b;
    }

    @WebMethod
    public Principal getById(int i) {
            return manager.getById(i);
    }

}

Add 方法有效,但 getById 因 NPE 而失败。我一直在调试 SpringBeanAutowiringSupport,它看起来像 ContextLoader.getCurrentWebApplicationContext() 返回 null。这意味着在初始化上下文之前正在调用 SpringBeanAutowiringSupport 构造函数。

我一直在尝试按照CXF 说明使用 Spring 运行应用程序。我现在没有这个代码,但是我已经将 PrincipalWebService 注册为一个 bean,创建了 spring 文件来配置 CXF 并通过它的 ID 作为端点添加了这个 bean。它在 Jetty 上运行良好,但在 JBoss 上却失败了。根据我配置 CXF 的方式,我收到了不同类型的异常,但根本原因是相同的 - JBoss 6 CXF 版本是针对 Spring 2.5 编译的,所以我们有库不一致。

有没有人有任何想法让 IoC 在 JBoss 6 上为 Jax-ws 服务工作?

4

3 回答 3

9

Ok, I've found a workaround. All we need to do is to move dependency injection to @PostConstruct method:

@PostConstruct
public void init() {
    SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}
于 2011-03-18T11:19:02.203 回答
2

您应该使用 jaxws:endpoint 在 spring 上下文中注册您的端点,并使用 implementationor 属性引用您的 bean。例如:

<jaxws:endpoint id="NotificationImpl"
                implementorClass="com.foo.ws.notification.NotificationImpl"
                implementor="#notificationImpl"
                serviceName="notification:Notification"
                address="/notification"
                xmlns:notification="http://notification.ws.foo.com">

端点实现:

@Component("notificationImpl")
@WebService(endpointInterface="com.foo.ws.notification.Notification")
public class NotificationImpl implements Notification  {

  @Autowired MessagingService messagingService = null;

  //...
}
于 2011-03-18T12:53:53.720 回答
0

我有同样的问题,但在 WebLogic 上,我已经按照这里的描述解决了它https://jira.springsource.org/browse/SPR-5652

于 2013-05-24T13:09:49.957 回答