Java 创建bean时出错,无法解析匹配的构造函数(提示:为简单参数指定index/type/name参数以避免类型歧义)
我有一个java应用程序maven项目,它有一个父根。 该应用程序在根目录下的其他项目中具有依赖项,当该应用程序初始化上下文时,将引发错误:Java 创建bean时出错,无法解析匹配的构造函数(提示:为简单参数指定index/type/name参数以避免类型歧义),java,xml,spring,maven,Java,Xml,Spring,Maven,我有一个java应用程序maven项目,它有一个父根。 该应用程序在根目录下的其他项目中具有依赖项,当该应用程序初始化上下文时,将引发错误: [LogFactory from sun.misc.Launcher$AppClassLoader@131165903] Created object org.apache.logging.log4j.jcl.LogFactoryImpl@173728231 to manage classloader sun.misc.Launcher$AppClassL
[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>
我确实尝试在构造函数arg中添加索引name,但没有成功
有什么想法吗?对我来说,初始化所有实例通用的静态变量的构造函数似乎不合适,为什么不使用静态方法呢?或者您想要不可变的字段,但每个实例都不同?在这种情况下,使用final而不是static关键字。这个构造函数的存在是因为我想从属性文件接收值,当我在xml中使用属性而不是在运行时使用构造函数arg时,其中的字段为空。我想我从来没有使用过这种配置文件Spring,但有些东西告诉我,当你使用它时,它正在寻找setter/getter,也许这是你的问题。另外,为什么要在声明单例的东西上使用静态方法?但这是另一场辩论,当然,我会停止污染这条线。
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() {}