Spring 会话 JDBC 集成

Spring session with JDBC integration

我是Spring Session 的新手,想使用嵌入式数据库来存储会话信息。我按照所有步骤 http://docs.spring.io/spring-session/docs/current/reference/html5/guides/httpsession-jdbc.html 使用 1.2 版的 spring-session-jdbc。0.but 仅使用 3.2.4 的 Spring-web 重复显示以下错误:

Caused by: org.postgresql.util.PSQLException: ERROR: relation "spring_session" does not exist 'Position: 13
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:419)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:365)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
    at org.springframework.jdbc.core.JdbcTemplate.doInPreparedStatement(JdbcTemplate.java:824)
    at org.springframework.jdbc.core.JdbcTemplate.doInPreparedStatement(JdbcTemplate.java:818)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:589)
    ... 21 more'

这个问题已经困扰我好几天了。请帮忙。

这里是xml配置

<bean class="org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessi‌​onConfiguration"/> 
<jdbc:embedded-database id="dataSource02" type="H2">
    <jdbc:script location="classpath:org/springframework/session/jdbc/schema-h2.sql"/>
</jdbc:embedded-database> 
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <constructor-arg ref="dataSource02"/>
</bean>

您的问题源于您使用多个数据源这一事实,因为在您配置辅助嵌入式数据源以存储会话时,提供的堆栈跟踪包括 PostgreSQL JDBC 驱动程序 类。

Spring 会话配置选择您的主要数据源 (PostgreSQL) 并期望在那里找到会话表。

我建议您使用主数据源来存储会话数据,但是如果您坚持要为此目的使用 secondary/embedded 数据源,则需要覆盖 JdbcOperationsSessionRepository bean 提供的 JdbcHttpSessionConfiguration#sessionRepository 使用您自己的实例,该实例是使用您的辅助数据源及其适当的事务管理器创建的。请注意,bean 必须命名为 sessionRepository 才能覆盖 JdbcHttpSessionConfiguration.

中的一个