JNDI资源不可用于Tomcat9中运行的Gemini Blueprint(在Bundle Activator中工作)



我有一个旧的Web应用程序,使用Eclipse RAP 3.0和Equinox OSGI Container以及Gemini Blueprint 1.0.2。

我可以在server.xml中定义我的JDNI值在context.xml中链接它们,并在我的web.xml中使用它们。

在我的launch.ini中,我使用父类加载器fwk,因此JNDI配置被传递到OSGI容器。

我的应用程序捆绑包可以读取这些值,例如在Bundle Activator:中

String xxx= InitialContext.doLookup("java:comp/env/xxx"); or
String xxx= new InitialContext().lookup("java:comp/env/xxx");

一些Bundle配置是通过Gemini Blueprint xml文件和SpringConfiguration Java类完成的。

<jee:jndi-lookup id="xxx" jndi-name="java:comp/env/xxx" />

这个部分不工作,我得到以下错误

Error creating bean with name 'xxx': Invocation of init method failed;
nested exception is javax.naming.NameNotFoundException:
Name [java:comp/env/xxx] is not bound in this Context. Unable to find [java:comp].

当我使用从gemini blueprint xml调用的Spring Java配置时,我会得到同样的错误。然后,像new InitialContext((.lookup("java:comp/env/xxx"(这样的语句就不起作用了,我得到了同样的异常。

我认为这必须使用Bundle Activator Code和Gemini BlueprintExtender Thread不同的类加载器,但我不知道如何解决这个问题。

我找到了一个可以使用的解决方案。

如果我将JNDI查找从xml移动到Spring配置类中,那么我可以像这样更改init中的classloader:Thread.currentThread((.setContextClassLoader(this.getClass((.getClassLoader(;

在那之后,我的Lookups工作得很好。

我在这里找到了解决方案

Spring Boot可以与OSGi一起使用吗?如果没有,有没有计划拥有OSGi Spring Boot?。

相关内容

最新更新