首页 > 解决方案 > Spring Boot 类路径:指定的资源不存在

问题描述

我正在使用 h2 作为测试数据库。我已经添加了 sql 脚本,/src/main/resources但是 spring boot 总是失败并显示“指定的资源不存在。 ”错误。以下是配置

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.datasource.initialize=true
spring.datasource.schema=classpath:schema.sql
spring.datasource.data=classpath:data.sql

错误跟踪: https ://paste.ee/p/1kHwd

我在这个平台上引用了很多帖子,并尝试将路径更改为 classpath:/data.sql 但这并不奏效。我在飞行路线上面临同样的问题。不知何故,Spring 在资源中找不到这些脚本。

我在这里错过了什么吗?任何帮助表示赞赏。

标签: javaspringspring-boot

解决方案


尝试添加

   <resource> 
       <directory>${basedir}/src/main/resources</directory> 
   </resource>

在你的 pom 文件中


推荐阅读