【问题标题】:Multiple SQL import files in Spring Boot - no wildcards in classpath resource possibleSpring Boot 中的多个 SQL 导入文件 - 类路径资源中没有通配符
【发布时间】:2020-04-11 12:00:12
【问题描述】:

由于我无法对M.Deinums answer in another post here 发表评论,我必须提出一个全新的问题:

我注意到了

spring.datasource.data=file:/somepath/to/somewhere/init-*.sql

有效,但无效

spring.datasource.data=classpath:/init-*.sql

想知道为什么。在文档中没有找到任何线索。

【问题讨论】:

    标签: hibernate spring-boot


    【解决方案1】:

    由于目前的搜索机很难找到特殊字符, 花了一段时间才找到解决方案:

    能够解析一个 ResourcePatternResolver 实现 指定资源位置路径到一个或多个匹配资源。 源路径可以是一个简单的路径,它具有一对一映射到 一个目标资源,或者可能包含特殊的 "classpath*:" 前缀和/或内部 Ant 样式的正则表达式 (使用 Spring 的 AntPathMatcher 实用程序匹配)。后两者 是有效的通配符。

    取自:https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/io/support/PathMatchingResourcePatternResolver.html

    所以,解决方案是(注意星号):

    spring.datasource.data=classpath:/data.sql,classpath*:/init-*.sql
    

    【讨论】:

      猜你喜欢
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      • 2018-12-19
      • 2010-12-08
      • 2011-12-15
      • 2021-05-02
      相关资源
      最近更新 更多