Java教程

SpringBoot ? Table ‘codetest.SPRING_SESSION‘ doesn‘t exist

本文主要是介绍SpringBoot ? Table ‘codetest.SPRING_SESSION‘ doesn‘t exist,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

项目场景:

提示:这里简述项目相关背景:

保留现场:

Caused by: java.sql.SQLSyntaxErrorException: Table 'codetest.SPRING_SESSION' doesn't exist
  at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.25.jar:8.0.25]
  at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.25.jar:8.0.25]
  at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) ~[mysql-connector-java-8.0.25.jar:8.0.25]
  at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092) ~[mysql-connector-java-8.0.25.jar:8.0.25]
  at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040) ~[mysql-connector-java-8.0.25.jar:8.0.25]
  at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1348) ~[mysql-connector-java-8.0.25.jar:8.0.25]
  at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025) ~[mysql-connector-java-8.0.25.jar:8.0.25]
  at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeUpdate(FilterChainImpl.java:3253) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.filter.FilterAdapter.preparedStatement_executeUpdate(FilterAdapter.java:1092) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_executeUpdate(FilterEventAdapter.java:491) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeUpdate(FilterChainImpl.java:3251) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.wall.WallFilter.preparedStatement_executeUpdate(WallFilter.java:695) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeUpdate(FilterChainImpl.java:3251) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.filter.FilterAdapter.preparedStatement_executeUpdate(FilterAdapter.java:1092) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_executeUpdate(FilterEventAdapter.java:491) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeUpdate(FilterChainImpl.java:3251) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.filter.FilterAdapter.preparedStatement_executeUpdate(FilterAdapter.java:1092) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_executeUpdate(FilterEventAdapter.java:491) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeUpdate(FilterChainImpl.java:3251) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.executeUpdate(PreparedStatementProxyImpl.java:194) ~[druid-1.2.5.jar:1.2.5]
  at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeUpdate(DruidPooledPreparedStatement.java:255) ~[druid-1.2.5.jar:1.2.5]
  at org.springframework.jdbc.core.JdbcTemplate.lambda$update$2(JdbcTemplate.java:965) ~[spring-jdbc-5.3.7.jar:5.3.7]
  at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:651) ~[spring-jdbc-5.3.7.jar:5.3.7]
  ... 16 more

原因分析:

  1. pom.xml文件中引入了
<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-jdbc</artifactId>
</dependency>

解决方法:

  1. 在application.yml 或 application.properties 中添加
spring:
  session:
    # 在关系型数据库中设置spring会话
    store-type: jdbc
    # 为了使其自动创建,需要指定该设置。设置后,Spring将使用Spring -session-jdbcjar中正确的SQL初始化脚本
    jdbc:
      initialize-schema: always
spring.session.store-type =jdbc
spring.session.jdbc.initialize-schema =always
  1. 如果没有用到spring-session-jdbc删除该引用也可以解决报错

参考文章:

MySQLSyntaxErrorException: Table ‘***.SPRING_SESSION’ doesn’t exist

spring-session用mysql实现session共享实践

这篇关于SpringBoot ? Table ‘codetest.SPRING_SESSION‘ doesn‘t exist的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!