我有一个较老的Web应用程序,使用Eclipse 3.0和Equinox、OSGI容器和Gemini Blueprint 1.0.2。
我可以在server.xml中定义JDNI值,在context.xml中链接它们,并在我的web.xml中使用它们。
在我的launch.ini中,我使用父类加载器fwk,因此JNDI配置被传递给OSGI。
我的应用程序-Bundles可以读取这些值,例如在Bundle-Activator中:
String xxx= InitialContext.doLookup("java:comp/env/xxx"); or
String xxx= new InitialContext().lookup("java:comp/env/xxx");一些捆绑配置是通过Gemini文件和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蓝图xml调用的。然后像新的InitialContext().lookup("java:comp/env/xxx")这样的语句就不能工作了,我也得到了同样的例外。
我认为它必须与不同的类加载程序是不同的捆绑-激活-代码和双子座BlueprintExtender线程,但在无法解决它如何解决这个问题。
发布于 2022-08-08 09:05:46
我找到了一个我可以用的解决方案。
如果我将JNDI查找从xml移到我的类中,那么我可以像下面这样更改init中的类装入器: Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
在那之后,我的查找工作很好。
我在这里找到了那个解决方案
Can Spring Boot be used with OSGi? If not, any plans to have an OSGi Spring Boot?。
https://stackoverflow.com/questions/73235536
复制相似问题