创建bean时出错无法解析匹配的构造函数(提示:为简单参数指定索引/类型/名称参数以避免类型歧义)

时间:2014-09-14 10:06:01

标签: java xml spring maven

我有一个拥有父根的java应用程序(maven项目)。 应用程序在root下的其他项目中具有依赖关系,当此应用程序初始化上下文时,将引发错误:

[LogFactory from sun.misc.Launcher$AppClassLoader@131165903] Created object org.apache.logging.log4j.jcl.LogFactoryImpl@173728231 to manage classloader sun.misc.Launcher$AppClassLoader@131165903
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'retriableOperationExecutor' defined in file [C:\evergreen\lt-pcqc\app\Backend\Common\lab-common\target\classes\Spring\qcext-pclab-retriable-operation-executor-context.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:250)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1051)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:955)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at com.hp.alm.lab.common.spring.SpringContextLoader.loadContext(SpringContextLoader.java:44)

xml文件正在加载,并且由于某些原因,它找不到相关的构造函数,尽管它位于包含xml文件的同一个jar中。

保持对同一项目的依赖项的其他项目在jetty服务器上运行,没有任何例外。 这是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.xsd">

    <bean id="retriableOperationExecutor" class="com.hp.alm.lab.common.utils.RetriableOperationExecutor" scope="singleton">
        <constructor-arg name="Default_Count" index="0" type="int" value="${default_count:5}"/>
        <constructor-arg name="Initial_Sleep_Millis" index="1" type="int" value="${initial_sleep_millis:2000}"/>
        <constructor-arg name="Max_Sleep_Time" index="2" type="int" value="${max_sleep_time:30000}"/>
    </bean>
</beans>

,相关的构造函数是:

public class RetriableOperationExecutor {


    private static int DEFAULT_COUNT;
    private static int INITIAL_SLEEP_MILLIS;
    private static  int MAX_SLEEP_TIME;

    public RetriableOperationExecutor(int Default_Count,int Initial_Sleep_Millis,int Max_Sleep_Time) {
        DEFAULT_COUNT=Default_Count;
        INITIAL_SLEEP_MILLIS=Initial_Sleep_Millis;
        MAX_SLEEP_TIME=Max_Sleep_Time;
    }

    public RetriableOperationExecutor() {}

我确实尝试在constructor-arg中添加索引name,但没有任何运气。

任何想法?

0 个答案:

没有答案
相关问题