Search code examples
javaspringjax-wsjava-metro-framework

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


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.


Solution

  • 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;
        }
        ...
    }