我是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 .也许这会导致一些问题?
该应用程序是一个独立的应用程序.我也检查了所有罐子的双重性,我不认为这是问题的原因,因为错误与我自己的类有关.
此致,奥利弗
更新: 我删除了错误而不知道是什么原因造成的.
我做了什么:
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是使用FormulaKeyas键创建的,所以这可能会带来麻烦.如果有人知道答案,我真的很想知道.
San*_*osh 25
这是我到目前为止可以收集的内容:
java.lang.LinkageError当有两个类加载器参与加载类时,会出现错误.my.project.formula.FormulaKey由一个类加载器加载,然后注释处理中涉及的类加载器再次加载它.my.project.formula.FormulaKey延迟,因为从XML加载上下文时不再引用它. | 归档时间: |
|
| 查看次数: |
24281 次 |
| 最近记录: |