当前使用版本(必须填写清楚,否则不予处理)
使用3.2.0版本spring boot starter
该问题是怎么引起的?(最新版上已修复的会直接close掉)
spring cloud工程中,使用h2的内存数据库,报表找不到。
重现步骤
详见https://github.com/brodxie/spring-cloud-and-docker中9892a2b75d58f185835fed8637678ff3da2ee2ef版本代码。provider-user的com.github.brodxie.springcloudanddocker.provider.user.test.ProviderUserTests#listUser方法执行会报错。
pom文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>spring-cloud-and-docker</artifactId>
<groupId>com.github.brodxie</groupId>
<version>1.0.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>provider-user</artifactId>
<dependencies>
<dependency>
<groupId>com.github.brodxie</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
配置如下
spring:
profiles:
active: standalone,peer1
application:
name: provider-user
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:microservice
schema: classpath:sql/schema.sql
data: classpath:sql/data.sql
h2:
console:
enabled: true
cloud:
service-registry:
auto-registration:
enabled: false
eureka:
client:
register-with-eureka: false
fetch-registry: false
instance:
prefer-ip-address: true
instance-id: ${eureka.instance.hostname}:${server.port}/${spring.application.name}
logging:
level:
root: info
com.github.brodxie: debug
---
server:
port: 8001
spring:
profiles: peer1
eureka:
instance:
hostname: peer1
---
server:
port: 8002
spring:
profiles: peer2
eureka:
instance:
hostname: peer2
---
spring:
profiles: standalone
eureka:
client:
service-url:
defaultZone: http://user:111111@peer1:8761/eureka/
---
spring:
profiles: ha
eureka:
client:
service-url:
defaultZone: http://user:111111@peer1:8761/eureka/,http://user:111111@peer2:8762/eureka/
报错信息
org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: org.h2.jdbc.JdbcSQLException: Table "T_USER" not found; SQL statement:
SELECT id,balance,name,username FROM t_user [42102-197]
### The error may exist in com/github/brodxie/springcloudanddocker/provider/user/dao/UserDAO.java (best guess)
### The error may involve com.github.brodxie.springcloudanddocker.provider.user.dao.UserDAO.selectList
### The error occurred while executing a query
### SQL: SELECT id,balance,name,username FROM t_user
### Cause: org.h2.jdbc.JdbcSQLException: Table "T_USER" not found; SQL statement:
SELECT id,balance,name,username FROM t_user [42102-197]
; bad SQL grammar []; nested exception is org.h2.jdbc.JdbcSQLException: Table "T_USER" not found; SQL statement:
SELECT id,balance,name,username FROM t_user [42102-197]
Comment From: jabezGit
我在MP 3.3.1 版本上同样遇到这个问题。正常使用H2数据库,没有问题,一旦集成Spring cloud 使用H2就找不到表,使用Mysql 操作就没有问题。请作者看看呢
Comment From: jabezGit
报错: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Method queryTotal execution error of sql :
SELECT COUNT(1) FROM gls_cors_account
The error may exist in com/xxx/dal/mapper/GlsCorsAccountMapper.java (best guess)
The error may involve com.xxx.dal.mapper.GlsCorsAccountMapper.selectPage
The error occurred while executing a query
Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Method queryTotal execution error of sql :
SELECT COUNT(1) FROM gls_cors_account