相关疑难解决方法(0)

Spring java.lang.LinkageError:loader constraint violation:loader以前为名为X的其他类型启动加载

我是Spring的新手,使用的是Spring 3.2.2.我有一些豆子,我通过<constructor-arg>它注入工作正常.现在我想注入一些@Autowired完全出错的bean .我这样做了:

beans.xml中:

<context:annotation-config />
<bean id="formulaFactory" class="my.project.formula.impl.GenericFormulaFactory"
    factory-method="getInstance">
<qualifier value="formulaFactory"></qualifier>
</bean>
Run Code Online (Sandbox Code Playgroud)

Java来源:

@Autowired
@Qualifier("formulaFactory")
private FormulaFactory formulaFactory;
Run Code Online (Sandbox Code Playgroud)

(更改限定符或将其删除没有任何区别......)

我收到这个错误:

java.lang.LinkageError: loader constraint violation: loader (instance of org/springframework/context/support/ContextTypeMatchClassLoader$ContextOverridingClassLoader) previously initiated loading for a different type with name "my/project/formula/FormulaKey"

我想知道为什么会出现这个错误.特别是这种类型FormulaKey让我感到恼火.当我将@Autowired注释与其他bean一起使用时,它可以工作.

我必须提到我通过getInstance方法将GenericFormulaFactory实现为singleton .也许这会导致一些问题?

该应用程序是一个独立的应用程序.我也检查了所有罐子的双重性,我不认为这是问题的原因,因为错误与我自己的类有关.

此致,奥利弗

更新: 我删除了错误而不知道是什么原因造成的.

我做了什么:

  1. 删除工厂实现的getInstance()方法和单例性质
  2. 将工厂接口添加到处理程序类构造函数(以及constructor-argxml中)

现在我可以使用xml配置实现并将其与@Autowired注释一起使用.

XML:

<bean id="formulaHandler" class="my.project.formula.impl.DefaultFormulaHandler">
    <constructor-arg ref="formulaFactory" />
</bean>
<bean id="formulaFactory" class="my.project.formula.impl.GenericFormulaFactory" />
Run Code Online (Sandbox Code Playgroud)

仍然想知道为什么错误首先出现.在工厂的实现中,a HashMap是使用FormulaKey …

java spring

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

spring ×1