A name space binding is a key-value pair that can be used by one or more applications in a WebSphere cell. For example, there could be a name space binding called "Greeting" that has a value of "Hello World". Applications can then use the "Greeting" name space binding to get the "Hello World" value. This provides a way to have a single location for the key-value pair, instead of having numerous applications coded with the "Hello World" value.
Create a name space binding
- In the left panel of the WebSphere admin console, expand Environment > Naming, and select Name space bindings.
- Select a scope for the name space binding.
- Select New.
- Select String or EJB or CORBA or Indirect and select Next. In this tutorial, String is selected.
- For Binding Identifier and Name in name space relative to lookup name prefix 'cell/persistent/', enter a key (Greeting in this example).
- For String value, enter a value (Hello World in this example).
- Select Next.
- Select Finish.
- Select Save.
Restart the JVMs that contain the application that will use the name space binding. Once this is done, you shouldn't need to restart the JVMs again, as changes to the name space binding value will happen dynamically. In other words, if you change the value to "Greetings Earth", the applications using the name space binding will start to use "Greetings Earth" instead of "Hello World".
The name space bindings will be stored in the namebinding.xml file, which is located at was_home/profiles/your_profile/config/cells/your_cell/namebinding.xml.
~]# cat namebindings.xml <namebinding:String name="Greeting" value="Hello World" />
You should now be able to use the name space binding in your Java app. In this example, a string object called "sayHi" is created, and the object will obtain the value associated with the Greeting key (Hello World).
InitialContext ctx = new InitialContext(); String sayHi = (String)ctx.lookup("cell/persistent/Greeting");
The Hello World value can then be printed.
If using Liberty, the following can be added to server.xml to create the key-value pair.
<featureManager> <feature>jndi-1.0</feature> </featureManager> <jndiEntry jndiName="cell/persistent/Greeting" value="Hello World"/>