JBoss 6 + Spring 3.0.5 + JAX-WS / CXF [英] JBoss 6 + Spring 3.0.5 + JAX-WS/CXF

查看:94
本文介绍了JBoss 6 + Spring 3.0.5 + JAX-WS / CXF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的项目使用Spring 3.0.5在JBoss 6上运行。一切顺利,直到我们尝试使用JAX-WS实现一些Web服务。如果我尝试做一些简单的WS(像添加2个数字),它只是工作 - 我把注释和添加注释类作为一个servlet。
但是如果我尝试让我的JAX-WS类填充依赖关系,事情会变得更加困难。



这是我的代码:

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

@Autowired
private校长经理;

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

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

}

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



我一直在尝试以下 CXF使用Spring运行应用程序的说明。我现在没有这个代码,但是我已经将PrincipalWebService注册为一个bean,创建了spring文件来配置CXF,并通过它的ID作为端点添加了这个bean。它在Jetty上表现很好,但在JBoss上失败。根据我如何配置CXF,我一直在接收不同种类的异常,但根本原因是相同的 - JBoss 6 CXF版本是针对Spring 2.5编译的,所以我们有库不一致。有没有人有任何想法可以让JoC在JBoss 6上为Jax-ws服务工作?

解决方案

好的,我找到了一个解决方法。所有我们需要做的是将依赖注入移动到@PostConstruct方法:

  @PostConstruct 
public void init {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}


We've got our project running on JBoss 6 with Spring 3.0.5. Everything went smooth until we tried to implement some Web Services with JAX-WS. If I try doing some simple WS (like adding 2 numbers), it just works - I put annotations and add annotated class as a servlet. But things are getting harder if I try to have my JAX-WS classes populated with dependencies.

Here's my code:

@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 method works, but getById fails with NPE. I've been debugging SpringBeanAutowiringSupport and it looks like ContextLoader.getCurrentWebApplicationContext() returns null. It means SpringBeanAutowiringSupport constructor is being called before context is initialized.

I've been trying following CXF instructions on running app with Spring. I don't have this code right now, but I've registered PrincipalWebService as a bean, created spring file to configure CXF and added this bean via it's ID as an endpoint. It went good on Jetty, but failed on JBoss. I've been receiving different kinds of exceptions depending on how I configure CXF, but root cause was the same - JBoss 6 CXF version is compiled against Spring 2.5, so we had library inconsistency.

Does anyone has any ideas of getting IoC working for Jax-ws services on JBoss 6?

解决方案

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);
}

这篇关于JBoss 6 + Spring 3.0.5 + JAX-WS / CXF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆