我正在开发具有多个 OSGi 捆绑包的项目,部署在 ServiceMix 上(FuseESB 编译,v. 4.3.1)。问题是,其中一个捆绑包连接到 WebLogic 上的 EJB,因此它嵌入了 weblogic.jar。
该解决方案正在运行,但是需要一个技巧。该捆绑包通过 OSGi 导出 Spring 服务。此服务导入到另一个捆绑包中,该捆绑包是系统的入口点。当从这个包调用服务时,weblogic 类是不可见的。工作技巧是在以下方面包装 Spring 服务,临时切换类加载器:
public Object profileInventory(ProceedingJoinPoint pjp) throws Throwable {
Object output = null;
ClassLoader clOld = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(pjp.getTarget().getClass().getClassLoader());
output = pjp.proceed();
} finally {
Thread.currentThread().setContextClassLoader(clOld);
}
return output;
}
据我了解,该服务是使用条目包中的类加载器调用的,而不是使用嵌入 weblogic 的包中的类加载器调用的,并且对于这个类加载器,嵌入的依赖类是不可见的。在类似的情况下,导出的 Spring 服务可以使用其捆绑包中的私有导入和私有包,但对于嵌入式 jar,情况并非如此。
我的问题是:嵌入 jar 是否如此具体,以至于只有当调用源自嵌入包(或使用类加载器切换技巧)时,才能看到嵌入的类,或者在嵌入包时需要指定更多内容,我忘记了去做?
我正在使用 maven-bundle-plugin
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <configuration> <instructions> <Bundle-Name>${pom.artifactId}</Bundle-Name> <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName> <Embed-Dependency> weblogic;scope=*, </Embed-Dependency>