我正在尝试使用 Spring和 wx-xmlrpc一起。问题是 XmlRpcClient有一个setConfig()不遵循 Java Bean 规范的方法:setter 和 getter 不使用相同的类。所以当我有以下 context.xml 时,Spring 会提示:
<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的返回类型?
有没有办法覆盖它?我知道我可以为这个 bean 写一个特定的工厂,但在我看来这不是我最后一次发现这种问题。我经常使用质量可疑的遗留代码......能够使用 Spring XML 配置将是一个很大的帮助!
最佳答案
为该类编写一个 FactoryBean 并让它调用正确的 setter。
关于java - 如何使用 Spring 在不遵循 Java bean 规范的 setter 中注入(inject)对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1215048/