Spring bean实例化异常集合

时间:2011-03-16 06:30:34

标签: spring inversion-of-control

Spring尝试实例化实现AbstractSet<Channel>的bean时抛出以下异常。

  

无法创建Collection类型的副本[org.jboss.netty.channel.group.DefaultChannelGroup] - 按原样注入原始集合

<bean id="defaultChannelGroup" class="org.jboss.netty.channel.group.DefaultChannelGroup" scope="prototype"></bean>

<bean id="client" class="com.menacheri.Client">
   <property name="id" value="6"></property>
   <property name="gameRoomChannelGroup" ref="defaultChannelGroup"></property>
</bean>

关于我做错的任何想法?

1 个答案:

答案 0 :(得分:0)

Spring 3.0.5似乎有更好的错误消息,我找不到你提供的那个。以下是可能的原因(来自Spring的错误):

  • Collection of type [] returned null Iterator
  • Cannot access Collection of type [] - injecting original Collection as-is
  • Cannot create copy of Collection type [] - injecting original Collection as-is
  • Collection type [] seems to be read-only - injecting original Collection as-is

尽管如此,尝试将您尝试注入的集合包装成一个全新的集合,如下所示:

<bean id="wrappedSet" class="java.util.HashSet">
    <constructor-arg>
        <ref bean="defaultChannelGroup"/>
    </constructor-arg>
</bean>

...而是注入wrappedSet。可能有帮助,只是一个猜测。

相关问题