我正在尝试使用spring数据来测试kotlin和spring boot。
id("org.springframework.boot") version "2.1.8.RELEASE"
我在schema-*.sql
中有一些src/main/resources
文件。我把它放在我的application.properties
spring.datasource.schema=/sql/schema-*.sql
然后我制作了一个基于小型弹簧启动ApplicationRunner
的应用程序(因此设置了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
有什么想法我应该做些什么才能使它起作用?
答案 0 :(得分:1)
尝试使用spring.datasource.schema=classpath:sql/schema-*.sql
。