bean中的Spring 3 init映射

时间:2016-06-20 13:27:03

标签: java spring

我有以下bean设置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="SMTPPlugin" class="com.org.proj.plugins.SMTPPlugin" />

    <bean id="AnotherPlugin" class="com.org.proj.plugins.export.AnotherPlugin" />

    <bean id="PluginBaseService" class="com.proj.plugins.PluginBaseService">
        <property name="plugins">
             <map key-type="java.lang.String" value-type="com.proj.common.plugins.interfaces.IPluginBase">              
                <entry key="SMTP" value-ref="SMTPPlugin" />
                <entry key="ANOTHER" value-ref="AnotherPlugin" />
            </map>
        </property>
    </bean>
</beans>

在PluginBaseService内部我有String,IPluginBase的映射,我想在那里注入bean SMTPPlugin和AnotherPlugin。两者都是实现IPluginBase接口。但是我得到了以下异常:

java.lang.IllegalStateException: Cannot convert value of type [com.org.proj.plugins.SMTPPlugin] to required type [com.proj.common.plugins.interfaces.IPluginBase] for property 'plugins[SMTP]': no matching editors or conversion strategy found

我真的应该使用一些转换器来完成这项工作吗?或者我该如何修复它?

由于

1 个答案:

答案 0 :(得分:0)

您在SMTPPlugin中缺少公共默认构造函数。