Wiki Markup |
---|
{scrollbar} |
Anchor | ||||
---|---|---|---|---|
|
7. JNDI integration
ServiceMix NMR includes a JNDI / OSGi integration based on OSGi RFC-0142.
Creating the InitialContext
No specific setup is need to create the InitialContext:
Code Block |
---|
Context ctx = new InitialContext(); |
The default context is a writable JNDI tree.
Accessing OSGi services
From the InitialContext, you can retrieve OSGi services using the following syntax:
Code Block |
---|
osgi:services/<interface>[/<filter>] |
For example:
Code Block |
---|
InitialContext context = new InitialContext(); ExampleService = (ExampleService) context.lookup("osgi:services/com.example.ExampleService"); |
Naming SPI
The JNDI integration uses the OSGi registry to lookup a javax.naming.spi.InitialContextFactoryBuilder
. If you want to use another provider for JNDI, you need to register such a service in the OSGi registry.
Note that in all cases, OSGi services will be available using the osgi:services/
URL.