即使所需的 JAR 位于 Bundle-classpath 中,OSGI 类也不可见

发布于 2024-12-17 04:36:41 字数 1584 浏览 0 评论 0原文

我们正在使用基于 Equinox 的 OSGI 框架来运行多个包。
我们的捆绑包在捆绑包类路径中具有依赖 JAR,并且依赖 JAR 与其余类和资源一起打包在单个 JAR/WAR 文件中。 但是我们在运行多个这样的捆绑包时遇到了问题。
说,
捆绑包 A:经过充分测试/工作的 JAR 捆绑包。包含捆绑包类路径中的所有依赖 JAR 以及内部(名为 lib 的文件夹下)的所有依赖 JAR。仅部署此捆绑包进行测试时工作正常

捆绑包 B:与捆绑包 A 类似。单独部署时再次工作

但是当两个捆绑包一起加载时,OSGI 无法从捆绑包的捆绑包类路径中提到的 JAR 加载类加载第二。第一个加载的包运行良好,而第二个加载的包失败。

目前,当 SPRING 尝试加载 javax.persistence.QueryHint 类时,会出现此问题。

我们使用 xxxx-EntityManager.xml 创建一个数据源,在其中创建 entityManagerFactory

使用的依赖 JAR:(两个包中的 JAR 相同)

  • Spring:3.0.6.RELEASE JARS
  • Hibernate:3.6.7 JARS
  • Hibernate-JPA:hibernate-jpa-2.0-api-1.0.1.Final.jar

异常: PropertyAccessException 1:org.springframework.beans.MethodInitationException:属性“targetDataSources”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [xxxx-EntityManager.xml] 中定义的名为“entityManagerFactory”的 bean 时出错:调用 init 方法失败;嵌套异常是 java.lang.IllegalArgumentException:接口 javax.persistence.QueryHint 从类加载器中不可见 在 org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102) 在 org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)

注意:

  • 两个 Bundle 都经过单独测试并且工作正常
  • 我们知道,我们可以提取而不是创建 Bundle-classpath捆绑包之外的第三方 JAR 并使用 import-package。但对于当前的要求,我们只需要父包内的第三方 JAR。

请求OSGI专家帮助我们。

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)

  • Spring: 3.0.6.RELEASE JARS
  • Hibernate: 3.6.7 JARS
  • Hibernate-JPA: hibernate-jpa-2.0-api-1.0.1.Final.jar

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:

  • Both the Bundles have been individually tested and working fine
  • We know that, instead of creating Bundle-classpath we can extract the thirdparty JARs outside of the bundles and use import-package. But for this current requirement, we need the third party JARs inside the parent bundle only.

Requesting OSGI experts to please help us out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

¢好甜 2024-12-24 04:36:42

我建议将您的依赖项放入单独的捆绑包中,并使所有包对其他捆绑包可见。然后将这些单独的包添加为依赖项(或者更好:仅导入所需的包而不是整个包!)。这样您就可以确保您的依赖项仅加载一次。我建议您当前的配置会导致类加载出现问题,因为类会被加载两次,并且很可能使用相同的 serialVersionUID。由于每个包都有自己的类加载器,因此第二个包将看不到辅助(未)加载的类。

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.

心是晴朗的。 2024-12-24 04:36:42

如果无法将 JAR 打包为单独的捆绑包,请指定 A 或 B 来包含所有 JAR,导出所有包,并使另一个捆绑包依赖于它(并从第二个捆绑包中删除 JAR)。

If you cannot package the JARs as separate bundles, designate eithe A or B to contain all JARs, export all packages, and make the other bundle depend on it (and remove the JARs from the second bundle).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文