Name space bindings from WebSphere

Home > Search
  by

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

  1. In the left panel of the WebSphere admin console, expand Environment > Naming, and select Name space bindings.
  2. Select a scope for the name space binding.
  3. Select New.
  4. Select String or EJB or CORBA or Indirect and select Next. In this tutorial, String is selected.
  5. For Binding Identifier and Name in name space relative to lookup name prefix 'cell/persistent/', enter a key (Greeting in this example).
  6. For String value, enter a value (Hello World in this example).
  7. Select Next.
  8. Select Finish.
  9. 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.

print sayHi;

 


Liberty

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"/>

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments