Yura Taras
Yura Taras

Reputation: 1293

JBoss 6 + Spring 3.0.5 + JAX-WS/CXF

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?

Upvotes: 2

Views: 7046

Answers (3)

bedla.czech
bedla.czech

Reputation: 1219

I hade same problem but on WebLogic and I have solved it as described here https://jira.springsource.org/browse/SPR-5652 .

Upvotes: 0

sourcedelica
sourcedelica

Reputation: 24040

You should register your endpoint in your spring context using jaxws:endpoint, and refer to your bean using the implementor attribute. For example:

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

Endpoint implementation:

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

  @Autowired MessagingService messagingService = null;

  //...
}

Upvotes: 2

Yura Taras
Yura Taras

Reputation: 1293

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

Upvotes: 9

Related Questions