I have my application running with spring web mvc framework without spring boot. Now I want to use spring session JDBC to store the session to the database used by the app. All the examples I found online are using spring boot, and if not using spring boot, the datasource config they use are EmbeddedDatabase
like this:
@Bean
public EmbeddedDatabase dataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("org/springframework/session/jdbc/schema-h2.sql").build();
}
I have my datasource configuration using HikariCP and I want the spring session to use this datasource config.
@Bean
public DataSource dataSource() {
HikariConfig config = new HikariConfig();
config.setDriverClassName(env.getRequiredProperty("jdbc.driver"));
config.setJdbcUrl(env.getRequiredProperty("jdbc.url"));
config.setUsername(env.getRequiredProperty("jdbc.username"));
config.setPassword(env.getRequiredProperty("jdbc.password"));
config.setMinimumIdle(env.getRequiredProperty("jdbc.pool.minimumIdle", Integer.class));
config.setMaximumPoolSize(env.getRequiredProperty("jdbc.pool.maximumPoolSize", Integer.class));
config.addDataSourceProperty("cachePrepStmts", env.getRequiredProperty("jdbc.prop.cachePrepStmts"));
config.addDataSourceProperty("prepStmtCacheSize", env.getRequiredProperty("jdbc.prop.prepStmtCacheSize"));
config.addDataSourceProperty("prepStmtCacheSqlLimit", env.getRequiredProperty("jdbc.prop.prepStmtCacheSqlLimit"));
HikariDataSource ds = new HikariDataSource(config);
return ds;
}
How can I use my current configuration to integrate with spring session?