Issue :
Getting Exception :
JAXBContext javax.xml.bind.JAXBContext.newInstance(java.lang.Class[]) throws
javax.xml.bind.JAXBException] threw exception; nested exception is
javax.xml.bind.JAXBException: ClassCastException: attempting to cast
jar:file:/C:/java6/jre/lib/rt.jar!/javax/xml/bind/JAXBContext.class to
bundle://80.0:1/javax/xml/bind/JAXBContext.class. Please make sure that you
are specifying the
proper ClassLoader.
at
org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:983)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:879)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
>From log , it is clear that JAXBContext.class has been loaded from two
different jar files , ideally it should be loaded from one jar file only.
In ServiceMix, there is jre.properties which explicitly says which packages
have to be loaded from rt.jar of jre and which packages not to be loaded.
And in this jre.propeties package containing JAXBContext has been commented
out which means that it should not be loaded from rt.jar.
But interesting thing is here that package containing JAXBContext is still
getting loaded from rt.jar.
So where and what went wrong !!!
To understand this,first i would like to tell classloader loads class in
below order if it finds class in top order
then it will load from there and will not look further.
1.Bootstrap
2.System ClassLoader
3.Web-INF/classes (any container weblogic,servicemix etc.)
4.Web-INF/lib
To find root cause for above exception,following steps can be performed
1.First add -verbose:class in karaf.bat just after %JAVA% .
Finally it should like this %JAVA% -verbose:class
2.After above change, console will show jar file names from where all
classes are being loaded .
3.Try to analyse console logs and try to find from JAXBContext class is
being loaded .
In my cases , i can see :
A....[Loaded javax.xml.bind.JAXBContext from
mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.2/1.9.0]
B....[Loaded javax.xml.bind.GetPropertyAction from
mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.2/1.9.0]
[Loaded javax.xml.bind.ContextFinder$1 from
mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.2/1.9.0]
[Loaded com.sun.xml.bind.v2.ContextFactory from
file:/C:/bea/modules/glassfish.jaxb_1.0.1.0_2-0-5.jar]
[Loaded javax.xml.bind.JAXBContext from C:\java6\jre\lib\rt.jar]
First one is being loaded as per expectationi.e. from
org.apache.servicemix.specs.jaxb-api-2.2/1.9.0
But in second one getting loaded from rt.jar which is not expectedone.
Here we can say that C:/bea/modules/glassfish.jaxb_1.0.1.0_2-0-5.jar is
forcing to load JAXBContext from rt.jar.
So we can say that there is some other software which is forcing to load
from rt.jar.
In my cases, bea/lib was in system class path i.e. system environment
variable in PATH.
So glassfish.jaxb_1.0.1.0_2-0-5.jar in weblogic lib was forcing to load
JAXBContext from rt.jar.
Once I removed weblogic/lib from system environment variable in PATH, my
issue was resolved because it started working according to service mix.
--
View this message in context:
http://servicemix.396122.n5.nabble.com/Servicemix-4-4-2-JaxbException-ClassCastException-after-deploying-a-camel-route-tp5714220p5716188.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.