Loading...

Using global variables in JNDI

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Custom variables can be stored via JNDI over the naming subsystem in JBoss. Following example were executed for Java EE 6 and JBoss EAP 6.4.

display help to add operation

/subsystem=naming/binding=*:read-operation-description(name=add)

add JNDI variable

/subsystem=naming/binding=java\:global\/metrics\/configuration\/directory:add(binding-type=simple, value="/etc/metrics", type="java.lang.String")

This JNDI variable can be used for resource injection.

usage in Java

@Resource(lookup="java:global/metrics/configuration/directory", type=String.class)
private String configDir;

read JNDI variable

/subsystem=naming/binding=java\:global\/metrics\/configuration\/directory:read-resource

remove JNDI variable

/subsystem=naming/binding=java\:global\/metrics\/configuration\/directory:remove

add variable and check

[standalone@localhost:9999 /] /subsystem=naming/binding=java\:global\/metrics\/configuration\/directory:add(binding-type
=simple, value="/etc/metrics", type="java.lang.String")
{"outcome" => "success"}
[standalone@localhost:9999 /] /subsystem=naming/binding=java\:global\/metrics\/configuration\/directory:read-resource
{
 "outcome" => "success",
 "result" => {
 "binding-type" => "simple",
 "cache" => undefined,
 "class" => undefined,
 "environment" => undefined,
 "lookup" => undefined,
 "module" => undefined,
 "type" => "java.lang.String",
 "value" => "/etc/metrics"
 }
}
Please remember the terms for blog comments.