0

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?

4
  • Try spring.datasource.schema=classpath:sql/schema-*.sql Commented Sep 20, 2019 at 13:59
  • @AlexeyUsharovski Cool, that worked, can you post as an answer please? Commented Sep 20, 2019 at 14:07
  • @AlexeyUsharovski Btw, any idea why changing WebApplicationType changes how this works? Commented Sep 20, 2019 at 14:08
  • Interesting about WebApplicationType but I have no suggestions for now worth to spread... Going to think about that. Commented Sep 20, 2019 at 14:44

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.