Skip to content

mkblogs/springboot-jndi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot JNDI Example

In this example, read the db.properties file and created JNDI DataSource using Tomcat JNDI Context

Setting for JNDI Context

 protected void postProcessContext(Context context) {
	 	log.info("in side post process");
        ContextResource resource = new ContextResource();
        resource.setName("jndiDataSource");
        resource.setType(DataSource.class.getName());
        resource.setProperty("driverClassName", driverClassName);
        resource.setProperty("url", url);
        resource.setProperty("username", username);
        resource.setProperty("password", password);
        context.getNamingResources().addResource(resource);
    }

Getting from JNDI Context

 JndiObjectFactoryBean bean = new JndiObjectFactoryBean(); 
 bean.setJndiName("java:/comp/env/jndiDataSource");
 bean.setProxyInterface(DataSource.class);
 bean.setLookupOnStartup(true);
 bean.afterPropertiesSet(); 

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages