Add classpath: to the path specified in spring.datasource.schema

An error occurs when starting Spring Boot

"InvalidConfigurationPropertyValueException: Property spring.datasource.schema with value'ServletContext resource [/schema.sql]' is invalid: The specified resource does not exist."

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sampleController': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sampleService': Unsatisfied dependency expressed through field 'jdbcTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdbcTemplate' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfiguration.class]: Unsatisfied dependency expressed through method 'jdbcTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; nested exception is org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException: Property spring.datasource.schema with value 'ServletContext resource [/schema.sql]' is invalid: The specified resource does not exist.
(Omission)
Caused by: org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException: Property spring.datasource.schema with value 'ServletContext resource [/schema.sql]' is invalid: The specified resource does not exist.
	at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.getResources(DataSourceInitializer.java:163) ~[spring-boot-autoconfigure-2.2.0.M5.jar!/:2.2.0.M5]
	at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.getScripts(DataSourceInitializer.java:146) ~[spring-boot-autoconfigure-2.2.0.M5.jar!/:2.2.0.M5]
	at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.createSchema(DataSourceInitializer.java:93) ~[spring-boot-autoconfigure-2.2.0.M5.jar!/:2.2.0.M5]
	at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker.afterPropertiesSet(DataSourceInitializerInvoker.java:62) ~[spring-boot-autoconfigure-2.2.0.M5.jar!/:2.2.0.M5]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.2.0.RC1.jar!/:5.2.0.RC1]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.2.0.RC1.jar!/:5.2.0.RC1]
	... 77 common frames omitted

Resolve by prefixing the file name with "classpath:"

"Classpath:" must be added before the file name specified in spring.datasource.schema or spring.datasource.data in application.properties.

application.properties


spring.datasource.url=jdbc:mysql://localhost:3306/testdb
spring.datasource.username=java
spring.datasource.password=cafebabe
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.initialization-mode=always
spring.datasource.schema=classpath:schema.sql
spring.datasource.data=classpath:data.sql
spring.datasource.sql-script-encoding=utf-8

Reference material

Recommended Posts

Add classpath: to the path specified in spring.datasource.schema
How to add a classpath in Spring Boot
How to specify the resource path in HTML import
4 Add println to the interpreter
How to add the same Indexes in a nested array
Add Extended Attributes to the file
Pass the i18n locale to JavaScript
How to add the delete function
Add a time stamp to the JAR file name in Gradle
Shorten the UUID to base64 in Swift.
Java reference to understand in the figure
Add the pre-built jar library to Android and call it in the framework
How to add jar file in ScalaIDE
Even though the property file path is specified in the -cp option, it is not recognized as a classpath.
How to get the date in java
How to get the absolute path of a directory running in Java
Add footnotes to Word documents in Java
Add SameSite attribute to cookie in Java
How to check the logs in the Docker container
Add empty data to the top of the list
I tried to organize the session in Rails
3 ways to import the library in Android Studio
When the server fails to start in Eclipse
[Java] (for MacOS) How to set the classpath
How to conditionally add html.erb class in Rails
How to build the simplest blockchain in Ruby
How to check Rails commands in the terminal
I want to get the value in Ruby
I want to change the path after new registration after logging in with multiple devises.
How to save a file with the specified extension under the directory specified in Java to the list
The right way to see the tomcat source in eclipse
I was addicted to the NoSuchMethodError in Cloud Endpoints
How to set the display time to Japan time in Rails
[Java] How to omit the private constructor in Lombok
I tried to organize the cases used in programming
I want to embed any TraceId in the log
Tokoro I rewrote in the migration from Wicket 7 to 8
[Java] How to extract the file name from the path
Understand the characteristics of Scala in 5 minutes (Introduction to Scala)
PKIX path building failed: Add SSL certificate to java
Source used to get the redirect source URL in Java
Let's stop writing the spec path in the code in the comments
[Java] Get the file path in the folder with List
Java classes and instances to understand in the figure
[Swift] Use UserDefaults to save data in the app
If you want to recreate the instance in cloud9
How to debug the generated jar file in Eclipse
I tried to implement the Euclidean algorithm in Java
[Rails] How to display an image in the view
I want to add a delete function to the comment function