在Spring Boot中使用JDBC和Spring Data JPA为我的会话Spring创建单独的数据源
我是spring-boot的新手,我想使用h2数据库与jdbc配置spring会话,但是它没有在我的h2嵌入式数据库中创建数据库和表,而是在PostgreSQL中使用PostgreSQL创建它我在应用程序属性文件中配置的数据源。如何使我的spring应用程序仅使用嵌入式h2数据库存储会话,而又不与JPA的PostgreSQL数据源冲突
I am a newbie in spring-boot and i want to configure my spring session with jdbc using h2 database, but it does not create a database and table in my h2 embedded database, it creates it in the PostgreSQL, using the PostgreSQL data source i configured in my applications properties file. How do i make my spring app use my embedded h2 db for storing sessions only while not conflicting with the PostgreSQL data source for my JPA
https://github.com/eshiett1995/SessionProject 。我希望有人可以帮助我完成该会话
https://github.com/eshiett1995/SessionProject. i would love if someone could help me with the session
检查 https://github.com/nomanbplmp/CustomSessionStoreExample 查看完整的示例。
会话存储与主数据库以外的其他存储一起使用,需要提供自定义会话存储库并覆盖如下所示的spring内部。
In order to make session store work with other than primary database it is required to provide custom session repository and override spring's internal as given below.
@Configuration
@EnableJdbcHttpSession
class SessionConfig {
@Bean
public JdbcOperationsSessionRepository sessionRepository(){
DataSource ds = DataSourceBuilder.create().driverClassName("org.h2.Driver").username("sa").url("jdbc:h2:file:~/test").build();
return new SessionRepo(ds,new DataSourceTransactionManager(ds));
}
}
class SessionRepo extends JdbcOperationsSessionRepository {
public SessionRepo(DataSource dataSource, PlatformTransactionManager transactionManager) {
super(dataSource, transactionManager);
}
}