levant pied
levant pied

Reputation: 4501

Kotlin and spring boot data resource exception

I'm trying out kotlin and spring boot with spring data.

id("org.springframework.boot") version "2.1.8.RELEASE"

I have some schema-*.sql files in src/main/resources. I put this in my application.properties

spring.datasource.schema=/sql/schema-*.sql

I then made a small spring boot ApplicationRunner-based app (so set WebApplicationType.NONE) and these all get executed as expected and the app starts fine.

@SpringBootApplication
private class MainApp(): ApplicationRunner { ... }

fun main(args: Array<String>) {
  runApplication<MainApp>(*args) {
    webApplicationType = WebApplicationType.NONE
  }
}

Now, when I change the above to WebApplicationType.SERVLET, I get the following:

Caused by: java.io.FileNotFoundException: ServletContext resource [/sql/] cannot be resolved to URL because it does not exist
    at org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:173) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:498) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:298) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.boot.devtools.restart.ClassLoaderFilesResourcePatternResolver.getResources(ClassLoaderFilesResourcePatternResolver.java:109) ~[spring-boot-devtools-2.1.8.RELEASE.jar:2.1.8.RELEASE]
    at org.springframework.context.support.GenericApplicationContext.getResources(GenericApplicationContext.java:233) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.jdbc.config.SortedResourcesFactoryBean.createInstance(SortedResourcesFactoryBean.java:76) ~[spring-jdbc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.jdbc.config.SortedResourcesFactoryBean.createInstance(SortedResourcesFactoryBean.java:42) ~[spring-jdbc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:142) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.doGetResources(DataSourceInitializer.java:175) ~[spring-boot-autoconfigure-2.1.8.RELEASE.jar:2.1.8.RELEASE]
    ... 89 common frames omitted

This exception goes away and the http server seems to be fine when I omment out:

spring.datasource.schema=/sql/schema-*.sql

Any ideas what I'm supposed to change to make this work?

Upvotes: 0

Views: 258

Answers (1)

Alexey  Usharovski
Alexey Usharovski

Reputation: 1442

Try that spring.datasource.schema=classpath:sql/schema-*.sql.

Upvotes: 1

Related Questions