Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.spring_session' doesn't exist - Spring Boot

前端 未结 3 889
星月不相逢
星月不相逢 2021-02-20 11:18

I am developing springboot-springsession-jdbc-demo. When I simply run the code I get the following error. It looks to me some property must need to set in app

3条回答
  •  暖寄归人
    2021-02-20 11:48

    I've just had a quite similar error while using spring-boot 2.0.5 (as opposed to 1.4.0 used by OP) with Postgres driver:

    org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [DELETE FROM spring_sessions WHERE EXPIRY_TIME < ?]; nested exception is org.postgresql.u
    til.PSQLException: ERROR: relation "spring_sessions" does not exist
      Position: 13
            at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:234) ~[spring-jdbc-5.0.8.RELEASE.jar!/:5.0.8.RELEA
    SE]
            // redacted...
            at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
    Caused by: org.postgresql.util.PSQLException: ERROR: relation "spring_sessions" does not exist
      Position: 13
            at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433) ~[postgresql-42.2.2.jar!/:42.2.2]
            at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2178) ~[postgresql-42.2.2.jar!/:42.2.2]
            // redacted...
            at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605) ~[spring-jdbc-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
            ... 16 common frames omitted
    

    According to documentation, setting up Spring Session backed by a relational database is as simple as adding a single configuration property to your application.properties:

    spring.session.store-type=jdbc
    

    Note that in order to get the session tables auto-created, I had to also specify:

    spring.session.jdbc.initialize-schema=always
    

    Once this setting specified, Spring used the correct SQL initialization script from spring-session-jdbc jar. My mistake was not specifying that option - in which case embedded was being used as default value.

提交回复
热议问题