Springboot+mybaits-plus+h2集成产生的一些问题(not found tables)

一、问题描述

org.h2.jdbc.JdbcSQLSyntaxErrorException:  Table "EP_MAPPING" not found (this database is empty);

大概就是说在引入mybatis-plus的依赖后,找不到数据库找不到表的问题。
排查方向:在引入mybatis+h2时,是可以正常运行的,但是改为mybtis-plus后,报错找不到tables。按理说,mybatis-plus集成了mybatis,一般不会出现这样的问题。
排查结果:版本问题,不兼容。
springboot 2.7.x
mybatis-plus 3.5.3.2
h2内嵌在springboot parent里边


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<parent>
		<groupId>org.springframework.bootgroupId>
		<artifactId>spring-boot-starter-parentartifactId>
		<version>2.7.14version>
		<relativePath/> 
	parent>
	<groupId>cn.isungent.irdgroupId>
	<artifactId>epdxartifactId>
	<version>0.0.1-SNAPSHOTversion>
	<name>epdxname>
	<description>Enterprise Data Platformdescription>
	<properties>
		<java.version>1.8java.version>
		<mybatis-plus.version>3.5.3.2mybatis-plus.version>
	properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-webartifactId>
			
		dependency>
		<dependency>
			<groupId>org.mybatis.spring.bootgroupId>
			<artifactId>mybatis-spring-boot-starterartifactId>
			<version>2.3.1version>
		dependency>
		<dependency>
			<groupId>com.h2databasegroupId>
			<artifactId>h2artifactId>
			<scope>runtimescope>
		dependency>
		<dependency>
			<groupId>com.mysqlgroupId>
			<artifactId>mysql-connector-jartifactId>
			<scope>runtimescope>
		dependency>
		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-devtoolsartifactId>
			<scope>runtimescope>
			<optional>trueoptional>
		dependency>
		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-configuration-processorartifactId>
			<optional>trueoptional>
		dependency>
		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-testartifactId>
			<scope>testscope>
		dependency>
		<dependency>
			<groupId>com.baomidougroupId>
			<artifactId>mybatis-plus-boot-starter-testartifactId>
			<version>${mybatis-plus.version}version>
			<scope>testscope>
		dependency>

		
		<dependency>
			<groupId>com.google.code.gsongroupId>
			<artifactId>gsonartifactId>
			<version>2.10.1version>
		dependency>
		
		<dependency>
			<groupId>org.apache.commonsgroupId>
			<artifactId>commons-lang3artifactId>
			<version>3.12.0version>
		dependency>
		
		<dependency>
			<groupId>org.mockitogroupId>
			<artifactId>mockito-coreartifactId>
			<version>4.11.0version>
			<scope>testscope>
		dependency>
		
		<dependency>
			<groupId>io.springfoxgroupId>
			<artifactId>springfox-swagger2artifactId>
			<version>3.0.0version>
		dependency>
		<dependency>
			<groupId>io.springfoxgroupId>
			<artifactId>springfox-boot-starterartifactId>
			<version>3.0.0version>
		dependency>
		<dependency>
			<groupId>io.springfoxgroupId>
			<artifactId>springfox-swagger-uiartifactId>
			<version>3.0.0version>
		dependency>

		<dependency>
			<groupId>com.baomidougroupId>
			<artifactId>mybatis-plus-boot-starterartifactId>
			<version>${mybatis-plus.version}version>
		dependency>

		<dependency>
			<groupId>com.baomidougroupId>
			<artifactId>mybatis-plus-extensionartifactId>
			<version>${mybatis-plus.version}version>
		dependency>
	dependencies>


	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.bootgroupId>
				<artifactId>spring-boot-maven-pluginartifactId>
			plugin>
		plugins>
	build>
project>

yml配置

spring:
  datasource:
    driverClassName: org.h2.Driver
    url: jdbc:h2:mem:test-db
  sql:
    init:
      data-locations: classpath:db/data.sql
      encoding: utf8
      schema-locations: classpath:db/schema.sql

  h2:
    console:
      enabled: true
      path: /h2-console

你可能感兴趣的:(spring,boot,后端,java,mybatis-plus,h2)