开发者

Spring bean instantiation exception for collection

开发者 https://www.devze.com 2023-02-17 06:45 出处:网络
Spring is throwing the following exception when it tries to instantiate a bean which implements AbstractSet<Channel>.

Spring is throwing the following exception when it tries to instantiate a bean which implements AbstractSet<Channel>.

Cannot create copy of Collection type [org.jboss.netty.channel.group.DefaultChannelGroup] - injecting original Collection as-is

<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>

Any id开发者_StackOverflow社区eas on what I am doing wrong?


Spring 3.0.5 seems to have a bit better error messages, I can't find the one you've provided. Here are the possible reasons (errors from Spring sources):

  • 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

Nevertheless, try wrapping the collection you are trying to inject in a new, fresh one, like this:

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

...and inject wrappedSet instead. Might help, just a guess.

0

精彩评论

暂无评论...
验证码 换一张
取 消