(TypeConverterDelegate.java:529) - 无法创建Collection类型的副本[java.util.ArrayList] - 按原样注入原始Collection

时间:2017-12-06 02:10:00

标签: java

我有程序:

public static void main(String[] args)
    {
        ApplicationContext ctx = ServiceLocator.getApplicationContext(); <-- error
.......}

它有以下错误消息:我想消除这个似乎来自JAVA [DEBUG]的错误。但该计划可以继续运行。我在谷歌搜索但没有运气。我也不知道代码在哪里错了。有可能解决这个问题吗?

14 Nov 2017 16:50:48,288 [DEBUG] (TypeConverterDelegate.java:529)  - Cannot create copy of Collection type [java.util.ArrayList] - injecting original Collection as-is
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection
    at org.springframework.beans.TypeConverterDelegate.convertToTypedCollection(TypeConverterDelegate.java:524)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:201)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:104)
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:415)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:657)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:984)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:886)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:558)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:852)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:422)
    at org.springframework.context.access.ContextSingletonBeanFactoryLocator.initializeDefinition(ContextSingletonBeanFactoryLocator.java:143)
    at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:384)
    at com.xxxx.ServiceLocator.getApplicationContext(ServiceLocator.java:24)
    at com.xxxx.main(mcrpt.java:115)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)

at com.xxxx.ServiceLocator.getApplicationContext(ServiceLocator.java:24)

  package com.xxxx;
        import org.springframework.beans.factory.BeanFactory;
        import org.springframework.beans.factory.access.BeanFactoryLocator;
        import org.springframework.beans.factory.access.BeanFactoryReference;
        import org.springframework.context.ApplicationContext;
        import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
        public class ServiceLocator {
            private static ApplicationContext applicationContext;

            protected ServiceLocator() {
            }

            public static ApplicationContext getApplicationContext() {
                if (applicationContext == null) {

                    BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator.getInstance("ApplicationContext.xml");
                    BeanFactoryReference bfr = locator.useBeanFactory("applicationContext");
                    BeanFactory factory = bfr.getFactory();
                    applicationContext = (ApplicationContext) factory;
                }
                return applicationContext;
            }

        }

的applicationContext.xml

<?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-2.0.xsd">

    <bean id="applicationContext"
        class="org.springframework.context.support.ClassPathXmlApplicationContext">
        <constructor-arg>
            <list>
                <value>ApplicationContext-properties.xml</value>
                <value>ApplicationContext-log4j.xml</value>
                <value>ApplicationContext-datasource.xml</value>
            </list>
        </constructor-arg>
    </bean>

</beans>    

1 个答案:

答案 0 :(得分:0)

您的bean定义不正确。

取代:

<bean id="applicationContext" class="org.springframework.context.support.ClassPathXmlApplicationContext">
    <constructor-arg>
        <list>
            <value>ApplicationContext-properties.xml</value>
            <value>ApplicationContext-log4j.xml</value>
            <value>ApplicationContext-datasource.xml</value>
        </list>
    </constructor-arg>
</bean>

<bean id="applicationContext" class="org.springframework.context.support.ClassPathXmlApplicationContext">
    <constructor-arg value="ApplicationContext-properties.xml" />
    <constructor-arg value="ApplicationContext-log4j.xml" />
    <constructor-arg value="ApplicationContext-datasource.xml" />
</bean>