How to use Spring DI in class constructed by another framework (using new)?

人盡茶涼 提交于 2019-12-12 01:52:52

问题


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?

来源:https://stackoverflow.com/questions/43881260/how-to-use-spring-di-in-class-constructed-by-another-framework-using-new

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!