문제

Background

I am embedding an OSGi runtime based on Apache Felix in the bridged mode in a Tomcat6 container. There are a bunch of JDBC connections specified in the conf/server.xml file in Tomcat6.

<Resource name="foo/bar" ... />

Question

The standard JNDI lookup doesn't seem to work from bundles deployed to the OSGi container.

ctx.lookup("java:comp/env/foo/bar");

Is there anything special that needs to be done for the OSGi runtime to be able to lookup resources registered in the parent Tomcat6 container?

도움이 되었습니까?

해결책

@Martin's comment got me thinking about multiple threads part. I got this to work by:

  1. Ensuring that ctx.lookup(...) is invoked in the BundleActivator. This is because, in the bridged mode, the ClassLoader of the thread running the Activator code can look up all Classes and Resources that are defined in the parent WAR file.
  2. Ensuring that the parent WAR's META-INF/context.xml exposes the JNDI resource via <ResourceLink global="foo/bar" name="foo/bar" type="javax.sql.DataSource"/>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top