I am using Spring Session with Postgres to store user sessions for a spring boot app. Spring Session is looking for the spring_session and spring_session_attributes tables in the public schema. Is there a way to tell Spring Session to look for the session tables in a schema other than public? spring.jpa.properties.hibernate.default_schema in application.properties seems to have no affect on this.
3 Answers
I managed to solve the problem by specifying the schema in the connect string/datasource URL as follows (also as described in an answer here):
spring.datasource.url=jdbc:postgresql://localhost:9999/db_name?currentSchema=<schema_name>
Still not sure why the spring.session.jdbc.schema property in application.properties has no affect on the schema used by spring session...

- 1
- 1

- 189
- 3
- 12
-
because that property is to specify where to find the initialization script, not the schema name – JeanValjean May 05 '23 at 06:22
Actually the parameter spring.session.jdbc.schema does not means the "database schema", but the SQL schema (the SQL that defines the data structure where the session data is stored).
The schemas for different DBs are available at:

- 11
- 1
You can set the table name to be used by Spring Session in your application.properties
like this:
spring.session.jdbc.table-name = MY_SCHEMA.SPRING_SESSION
As a result the SQL queries issued by Spring Session will go against the tables of your specified schema. See also org.springframework.session.jdbc.JdbcOperationsSessionRepository
.

- 1
- 1