How to inject @AutoWired Spring beans into a @WebService endpoint on EAP 6

Solution Verified - Updated -

Environment

  • JBoss Enterprise Application Platform (EAP)
    • 6.x
  • Spring

Issue

We have a @WebService endpoint which uses other Spring beans injected with @Autowired. If we extend SpringBeanAutowiringSupport so that they can be injected, it does not work because the injection is run before the spring context listener creates the context.

Resolution

  • Create an @PostConstruct method which calls SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);

Root Cause

  • There is no requirement that a context listener runs before any web service endpoints are created, only before the servlets. As such they cannot depend on it.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments