Spring java.lang.LinkageError: loader constraint violation: loader previously initiated loading for a different type with name X -


i new spring , use spring 3.2.2. have beans injected via <constructor-arg> works fine. wanted inject bean via @autowired totally went wrong. have done this:

beans.xml:

<context:annotation-config /> <bean id="formulafactory" class="my.project.formula.impl.genericformulafactory"     factory-method="getinstance"> <qualifier value="formulafactory"></qualifier> </bean> 

java source:

@autowired @qualifier("formulafactory") private formulafactory formulafactory; 

(changing qualifier or leaving out did not make difference...)

and error:

java.lang.linkageerror: loader constraint violation: loader (instance of org/springframework/context/support/contexttypematchclassloader$contextoverridingclassloader) initiated loading different type name "my/project/formula/formulakey"

i wonder why error comes up. type formulakey irritates me. when use @autowired annotation other bean, works.

i have mention implemented genericformulafactory singleton via getinstance method. maybe causes problems?

the application stand-alone app. checked jars duplicity , not assume cause of problem because error relates own classes.

regards, oliver

update: removed error without knowing cause it.

what did:

  1. remove getinstance() method , singleton nature of factory implementation
  2. added factory interface handler classes constructor (and constructor-arg in xml)

now can use xml configure implementation , use @autowired annotations too.

xml:

<bean id="formulahandler" class="my.project.formula.impl.defaultformulahandler">     <constructor-arg ref="formulafactory" /> </bean> <bean id="formulafactory" class="my.project.formula.impl.genericformulafactory" /> 

still wondering why error came in first place. in implementation of factory, hashmap created using formulakey key, maybe caused trouble. if knows answer, know it.

here gather far:

  1. the error java.lang.linkageerror comes in situation when there 2 classloaders involved in loading class.
  2. a classloader keeps track of classes loaded generating unique identifier contains qualified class name , classloader loaded it.
  3. when classloader receives reference of class loaded class loaded itself, results erroneous situation class can loaded once in classloading hierarchy.
  4. when custom classloaders involved, loading particular class, practice parent classloaders queried first if class loaded.
  5. in scenario, when custom classloader not query parent hierarchy , decided load class itself, there might case wherein class being loaded loaded classloader in parent hierarchy.
  6. follow this link know more it.
  7. for case, guess xml configuration , annotation processing done 2 different classloaders.
  8. in error scenario, my.project.formula.formulakey loaded 1 classloader , class loader involved in annotation processing loads 1 more time.
  9. when changed code, loading of my.project.formula.formulakey deferred no more referred while loading context xml .

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -