I have a data source that is setup & then, used by a third party software to execute sql. After the sql is run I have another bean that executes & closes the connection.
@Bean
public DataSource datasource() {
HikariConfig myconfig = new HikariConfig();
...
return new HikariDataSource(myconfig);
}
@Bean
@DependsOn("sqlproject")
public void closeConnection() throws SQLException {
Connection c = datasource().getConnection();
try {
c.close();
}
finally {
System.out.println(c.isClosed());
}
}
However, I can clearly still make local calls using that datasource connection to particular data. Should I not be calling datasource()
because this creates a new instance ? What am I doing wrong ?