Is there any difference between declaring The DataSource
in META-IF/context.xml
file and get it from the spring bean using the JNDI lookup (Approach 1), Or just declaring the DataSource
directly via Spring (Approach 2) like :
@Bean(destroyMethod = "close")
DataSource dataSource(Environment env) {
HikariConfig dataSourceConfig = new HikariConfig();
dataSourceConfig.setDriverClassName(env.getRequiredProperty(PROPERTY_NAME_DB_DRIVER_CLASS));
dataSourceConfig.setJdbcUrl(env.getRequiredProperty(PROPERTY_NAME_DB_URL));
dataSourceConfig.setUsername(env.getRequiredProperty(PROPERTY_NAME_DB_USER));
dataSourceConfig.setPassword(env.getRequiredProperty(PROPERTY_NAME_DB_PASSWORD));
return new HikariDataSource(dataSourceConfig);
}
I think the second approach is better because is not tied to a specefic Server, that means if we use the first approach and one day migrate to another Server we must adapt the strategie of the context file in the second server (not true ?).
Thanks