如何使用Spring在不遵循Java bean规范的setter中注入对象? [英] How to use Spring to inject an object in a setter that doesnt follow the Java bean specification?

查看:394
本文介绍了如何使用Spring在不遵循Java bean规范的setter中注入对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Spring wx-xmlrpc 在一起。问题是 XmlRpcClient setConfig( )方法不遵循Java Bean规范:setter和getter不使用相同的Class。所以当我有以下context.xml时Spring会抱怨:

I am trying to use Spring and wx-xmlrpc together. The problem is that XmlRpcClient has a setConfig() method that doesnt follow the Java Bean spec : the setter and the getter dont use the same Class. So Spring complaints when I have the following context.xml :

<bean id="xmlRpcClient" class="org.apache.xmlrpc.client.XmlRpcClient">
    <property name="config">
        <bean class="org.apache.xmlrpc.client.XmlRpcClientConfigImpl">
            <property name="serverURL" value="http://example.net" />
        </bean>
    </property>
</bean>

它说:Bean属性'config'不可写或具有无效的setter方法。 setter的参数类型是否与getter的返回类型匹配?

It says : Bean property 'config' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

有没有办法覆盖它?我知道我可以为这个bean写一个特定的工厂,但在我看来,这不是我最后一次发现这种问题。我使用质量可疑的遗留代码工作很多...能够使用Spring XML配置将是一个很大的帮助!

Is there a way to override that ? I know I could write a specific factory for this bean, but it seems to me that it is not the last time I find this kind of problem. I work a lot with legacy code of dubious quality ... Being able to use Spring XML configuration with it would be a great help !

推荐答案

为该类编写FactoryBean并让它调用正确的setter。

Write a FactoryBean for that class and have it call the correct setter.

这篇关于如何使用Spring在不遵循Java bean规范的setter中注入对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆