上下文:尝试测试一个spring boot应用,尝试通过src/test/resources/目录下的data.sql文件初始化数据
我在内存数据库中有以下内容:
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;
我还有以下 SQL 表:
CREATE TABLE `roles` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(60) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_nb4h0p6txrmfc0xbrd1kglp9t` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
这是我的插入语句(在 data.sql 中)
INSERT INTO roles(name) VALUES ("ROLE_USER");
当我运行我的 spring 单元测试时,我得到了这个错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #2 of URL [file:/Users/me/IdeaProjects/proj/out/test/resources/data.sql]: INSERT INTO roles(name) VALUES ("ROLE_USER"); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "ROLE_USER" not found; SQL statement:
INSERT INTO roles(name) VALUES ("ROLE_USER") [42122-198]
对我来说,一切看起来都是正确的......我正在使用一个简单的插入语句,在一个肯定存在的表上......我正在插入一个与列定义很好对应的值。但由于某种原因,它会抛出错误,说“ROLE_USER”列不存在,我不知道为什么。
红糖糍粑
慕桂英4014372
随时随地看视频慕课网APP
相关分类