We are using an Equinox based OSGI framework to run Multiple bundles.
Our bundles have dependent JARs in the Bundle-classpath and the dependent JARs are packaged along with the rest of the classes and resources in a single JAR/WAR file.
But we have a problem while running multiple such Bundles.
Say,
Bundle A: Fully tested/working JAR bundle. Contains all dependent JARs in the bundle classpath and all the dependent JARs inside (under a folder named lib). Working fine when tested by deploying only this bundle
Bundle B: Similar to Bundle A. Again working when deploying separately
But when both bundles are loaded together, OSGI is not able to load classes from JARs mentioned in the bundle-classpath for the bundle that is loaded second. The bundle that is loaded first runs fine, whereas the bundle loaded second fails.
This issue currently occurs while SPRING tries to load javax.persistence.QueryHint class.
We create a Data source using our xxxx-EntityManager.xml where we create our entityManagerFactory
Dependent JARs used: (Same JARs in both the bundles)
Exception:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'targetDataSources' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [xxxx-EntityManager.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: interface javax.persistence.QueryHint is not visible from class loader
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
Note:
Requesting OSGI experts to please help us out.
I recommend to put your dependencies in individual bundles and make all packages visible to other bundles. Then add these individual bundles as dependencies (or better: import only the required packages instead of the whole bundle!). This way you can ensure that your dependencies are loaded just once. I suggest that your current configuration leads to problems in class loading, as classes are loaded twice with most probably the same serialVersionUID. And since each bundle has its own classloader, the secondary (not) loaded class won't be visible to the second bundle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With