In this example, read the db.properties
file and created JNDI DataSource using Tomcat 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);
}
JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
bean.setJndiName("java:/comp/env/jndiDataSource");
bean.setProxyInterface(DataSource.class);
bean.setLookupOnStartup(true);
bean.afterPropertiesSet();