I am learning basics of EJB 3.0. I have managed to get a sample code up and running. Now I am doing a line by line analysis to have in-depth knowledge. But I am stuck at few lines where there is a lookup to find the required bean.
Can anyone please explain me in simple language the meaning and the need of the following lines?
Properties properties = new Properties();
properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces");
properties.setProperty(Context.PROVIDER_URL, "localhost:1099");
IniialContext context = null;
SamleEjbRemote cl = null;
try {
context = new InitialContext(properties);
cl = (SampleEjbRemote) context.lookup("SampleEjbBean/remote");
} catch (NamingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
What is the exact meaning of each of the 'key' and 'value' that is used in properties?
Rest of it is to put the 'properties' in the initial context instance. I have had a very vague idea of the above, but I want to clarify it very clearly. I would be glad if anyone could point me to any links or insights about the above lines.
Thanks in advance.
This class is the starting context for performing naming operations. All naming operations are relative to a context. The initial context implements the Context interface and provides the starting point for resolution of names. The initial context implementation is determined at runtime.
The actual home lookup name is determined by the application's deployment descriptors. The enterprise bean (EJB) resides in an EJB container, which provides an interface between the bean and the application server on which it resides.
An application resource file has the name jndi. properties. It contains a list of key/value pairs presented in the properties file format (see java. util.
Interface InitialContextFactoryThis interface represents a factory that creates an initial context. The JNDI framework allows for different initial context implementations to be specified at runtime. The initial context is created using an initial context factory.
Both properties configures JBoss JNDI HTTP InitialContext Factory Implementation
Official document here : http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch3.chapter.html
See chapter 3.2.1.2. The HTTP InitialContext Factory Implementation
java.naming.factory.initial: The name of the environment property for specifying the initial context factory, which must be org.jboss.naming.HttpNamingContextFactory.
java.naming.factory.url.pkgs: For all JBoss JNDI provider this must be org.jboss.naming:org.jnp.interfaces. This property is essential for locating the jnp: and java: URL context factories of the JBoss JNDI provider.
UPDATE:
I would recommend to use jndi.properties file in your class path
### JBossNS properties
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With