How to use @Resource WebServiceContext injection with Spring's @Transactional

adrianboimvaser picture adrianboimvaser · Apr 28, 2011 · Viewed 20.1k times · Source

I hava a Metro jax-ws webservice that looks more or less like this:

@WebService
@Transactional
public class UserManagementServiceImpl {

    @Resource
    private WebServiceContext context;

    ...
}

The WebServiceContext is allways null. However, if I remove @Transactional the WebServiceContext is injected.

Anybody knows a workaround?

Thanks.

Answer

adrianboimvaser picture adrianboimvaser · Apr 28, 2011

I've found a workaround. Use setter injection instead of field injection:

@WebService
@Transactional
public class UserManagementServiceImpl {

    private WebServiceContext context;

    @Resource
    public void setContext(WebServiceContext context) {
        this.context = context;
    }
    ...
}