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

前端 未结 1 947
野趣味
野趣味 2020-12-28 08:48

I am new to Spring and use Spring 3.2.2. I have some beans which I injected via which works fine. Now I wanted to inject some bean via <

相关标签:
1条回答
  • 2020-12-28 09:37

    Here is what I could gather so far:

    1. The error java.lang.LinkageError comes in a situation when there are two classloaders involved in loading a class.
    2. A classloader keeps track of the classes loaded by generating a unique identifier which contains the fully qualified class name itself and the classloader loaded it.
    3. When a classloader receives a reference of a class loaded by another class which is already loaded by itself, this results into erroneous situation as a class can be loaded only once in a classloading hierarchy.
    4. When custom classloaders are involved, for loading a particular class, the practice is that the parent classloaders are queried first if that class is already loaded.
    5. In the scenario, when a custom classloader does not query the parent hierarchy and decided to load the class itself, there might be case wherein the class being loaded is already loaded by some classloader in parent hierarchy.
    6. Read Kieviet, Frank's "The java.lang.LinkageError: loader constraint violation" demystified" to know more about it.
    7. For your case, I guess the XML configuration and Annotation processing is done by two different classloaders.
    8. In the error scenario, my.project.formula.FormulaKey is loaded by one classloader and then the class loader involved in annotation processing loads it one more time.
    9. When you changed the code, the loading of my.project.formula.FormulaKey is deferred as its no more referred while loading the context from XML .
    0 讨论(0)
提交回复
热议问题