简体   繁体   English

Spring 引导类路径:指定的资源不存在

[英]Spring boot classpath: The specified resource does not exist

I am using h2 as a database for testing.我正在使用 h2 作为测试数据库。 I have added sql scripts to /src/main/resources but spring boot always fails with " The specified resource does not exist. " error.我已将 sql 脚本添加到/src/main/resources但 spring 引导始终失败,并显示“指定的资源不存在。 ”错误。 Following are the configurations以下是配置

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

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

I have referred many posts on this platform and tried changing the path to classpath:/data.sql but this did not work as well.我在这个平台上引用了很多帖子,并尝试将路径更改为 classpath:/data.sql 但这也不起作用。 I am facing the same issue with the flyway.我在飞行路线上面临同样的问题。 Somehow Spring can not found these scripts in resources.不知何故 Spring 在资源中找不到这些脚本。

Am I missing something here?我在这里错过了什么吗? Any help is appreciated.任何帮助表示赞赏。

try to add尝试添加

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

in your pom file在你的 pom 文件中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Spring 引导中的类路径加载嵌套资源 - Loading nested resource from the classpath in Spring Boot Optaplanner-BenchmarkConfigResource在classLoader中不作为类路径资源存在 - Optaplanner - The benchmarkConfigResource does not exist as a classpath resource in the classLoader 无法打开类路径资源[spring / config / BeanLocations.xml],因为它不存在 - classpath resource [spring/config/BeanLocations.xml] cannot be opened because it does not exist Spring boot:如何在单元测试中从类路径读取资源 - Spring boot: How to read resource from classpath in unit test Spring框架启动不存在? - Spring framework boot does not exist? 指定的队列不存在 - AWS.SimpleQueueService.NonExistentQueue 与 Spring-Boot - The specified queue does not exist - AWS.SimpleQueueService.NonExistentQueue with Spring-Boot Spring Boot 1.5.2:类路径资源[]无法解析为URL,因为它不存在 - Spring Boot 1.5.2: class path resource [] cannot be resolved to URL because it does not exist Spring 启动和 Keycloak - 401 状态代码,即使资源不存在 - Spring Boot and Keycloak - 401 status code even when resource does not exist Spring类路径资源被覆盖 - Spring classpath resource overwritten Spring 引导类路径 - Spring Boot classpath
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM