How to use Spring DI in class constructed by anoth

2019-08-25 17:11发布

I am doing some work on a legacy SOAP app which uses Axis2. I would like to introduce some basic Spring injection. The app has an Axis2 service config that specifies:

<ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
    <ramp:timestampTTL>300</ramp:timestampTTL>  
    <ramp:timestampMaxSkew>300</ramp:timestampMaxSkew>
    <ramp:user>service</ramp:user>
    <ramp:encryptionUser>useReqSigCert</ramp:encryptionUser>
    <ramp:passwordCallbackClass>
        com.myapp.SomeCallbackHandler
    </ramp:passwordCallbackClass>

Which probably means that Axis2 instantiates SomeCallbackHandler using reflection (and ultimately new, which clashes with the way Spring works) and in that class I would like to inject a bean which is loaded via ContextLoaderListener:

@Component
public class SomeCallbackHandler implements CallbackHandler {

    @Autowired
    private InjectedConfigClass myConfig;

Since the scope of my refactoring is limited and I can't bypass the use of Axis2, is there any way I can still use a Spring injected bean in a callback class that is defined to Axis2 in its XML config?

0条回答
登录 后发表回答