【发布时间】:2020-01-21 14:20:59
【问题描述】:
我正在尝试使用弹簧数据的 kotlin 和弹簧靴。
id("org.springframework.boot") version "2.1.8.RELEASE"
我在src/main/resources 中有一些schema-*.sql 文件。我把这个放在我的application.properties
spring.datasource.schema=/sql/schema-*.sql
然后我制作了一个基于 ApplicationRunner 的小型 spring boot 应用程序(所以设置 WebApplicationType.NONE),这些都按预期执行,应用程序启动正常。
@SpringBootApplication
private class MainApp(): ApplicationRunner { ... }
fun main(args: Array<String>) {
runApplication<MainApp>(*args) {
webApplicationType = WebApplicationType.NONE
}
}
现在,当我将上面的内容更改为 WebApplicationType.SERVLET 时,我得到以下信息:
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
这个异常消失了,当我注释掉时,http 服务器似乎很好:
spring.datasource.schema=/sql/schema-*.sql
有什么想法我应该改变以使这项工作有效吗?
【问题讨论】:
-
试试
spring.datasource.schema=classpath:sql/schema-*.sql -
@AlexeyUsharovski 很酷,这行得通,你能发帖作为答案吗?
-
@AlexeyUsharovski 顺便说一句,知道为什么更改
WebApplicationType会改变其工作方式吗? -
对
WebApplicationType很感兴趣,但我目前没有任何值得传播的建议……会考虑一下。
标签: spring spring-boot kotlin spring-data