0% found this document useful (0 votes)
255 views3 pages

JNDI Lookup Wildfly and Spring - Jaehoo Weblog

This document discusses how to perform JNDI lookups from Wildfly application server in both Java code and Spring. It explains how to add JNDI resources to Wildfly's configuration file and lookup values by name. It also shows how to configure JNDI lookups in Spring by adding beans that reference the JNDI names. The values can then be retrieved from the application context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
255 views3 pages

JNDI Lookup Wildfly and Spring - Jaehoo Weblog

This document discusses how to perform JNDI lookups from Wildfly application server in both Java code and Spring. It explains how to add JNDI resources to Wildfly's configuration file and lookup values by name. It also shows how to configure JNDI lookups in Spring by adding beans that reference the JNDI names. The values can then be retrieved from the application context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

8/6/2019 JNDI lookup Wildfly and Spring – Jaehoo Weblog

Jaehoo Weblog

Blog personal de jaehoo

JNDI lookup Wildfly and Spring


mayo 8, 2019mayo 10, 2019

A quick reference to load JNDI resource from Wildfly application server. Let’s do this with java api and
spring.

Adding JNDI resources to wildfly

First, edit standalone/configuration/standalone.xml and add this lines into subsystem.

1 <subsystem xmlns="urn:jboss:domain:naming:2.0">
2 <bindings>
3 <simple name="java:global/MyString" value="MyValue"/>
4 <simple name="java:global/MyNumber" value="100" type="int"/>
5 </bindings>
6 </subsystem>

In Java api way

In java code you can retrieve with this:

https://jaehoo.wordpress.com/2019/05/08/jndi-lookup-wildfly-and-spring/ 1/3
8/6/2019 JNDI lookup Wildfly and Spring – Jaehoo Weblog
1 //Simple String
2 String myString = InitialContext.doLookup("global/MyString");
3
4 // Casting object
5 InitialContext initialContext = new InitialContext();
6 Integer myNumber= (Integer) initialContext.lookup("global/MyNumber");
7
8 //print
9 System.out.println("value:"+myString);
10 System.out.println("value:"+myNumber);

In Spring way

Or if you are using spring, into ApplicationContext add this:

1 <jee:jndi-lookup id="text" jndi-name="global/MyString"/>


2 <jee:jndi-lookup id="number" jndi-name="global/MyNumber"/>

But If you don’t use the prefix jee or if have older version:

1 <bean id="text" class="org.springframework.jndi.JndiObjectFactoryBean" p


2 <bean id="number" class="org.springframework.jndi.JndiObjectFactoryBean"

Then from the spring application context get the beans:

1 ApplicationContext applicationContext = new ClassPathXmlApplicationConte


2
3 String text= (String)applicationContext.getBean("text");
4 Integer number= (Integer)applicationContext.getBean("number");
5
6 System.out.println("result:"+text);
7 System.out.println("result:"+number);

Saludos

References

https://docs.jboss.org/author/display/WFLY10/Naming+Subsystem+Configuration
(https://docs.jboss.org/author/display/WFLY10/Naming+Subsystem+Configuration)
https://docs.jboss.org/author/display/WFLY8/JNDI+Reference
(https://docs.jboss.org/author/display/WFLY8/JNDI+Reference)
https://stackoverflow.com/questions/46686452/jboss-wildfly-how-to-bind-entries-in-local-jndi-
namespaces (https://stackoverflow.com/questions/46686452/jboss-wildfly-how-to-bind-entries-in-
local-jndi-namespaces)
https://developer.jboss.org/thread/238892 (https://developer.jboss.org/thread/238892)

https://jaehoo.wordpress.com/2019/05/08/jndi-lookup-wildfly-and-spring/ 2/3
8/6/2019 JNDI lookup Wildfly and Spring – Jaehoo Weblog

Publicado en: Development, General, Java, Spring Framework | Etiquetado: Java, Spring
This site uses Akismet to reduce spam. Learn how your comment data is processed.

CREA UN BLOG O UN SITIO WEB GRATUITOS CON WORDPRESS.COM.

https://jaehoo.wordpress.com/2019/05/08/jndi-lookup-wildfly-and-spring/ 3/3

You might also like