【问题标题】:exclude data.sql from Spring boot jar从 Spring Boot jar 中排除 data.sql
【发布时间】:2018-02-16 19:01:36
【问题描述】:

我正在尝试从 Spring Boot 应用程序 jar 中排除我的 data.sql 和 schema.sql。

到目前为止,我已经尝试了几个选项,但它们似乎都不起作用。这是我的 POM 配置。

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <activatedProperties>dev</activatedProperties>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <activatedProperties>prod</activatedProperties>
        </properties>
        <build>
            <resources>
                <resource>
                    <filtering>true</filtering>
                    <directory>src/main/resources</directory>
                    <excludes>
                        <exclude>data.sql</exclude>
                        <exclude>schema.sql</exclude>
                    </excludes>
                </resource>
            </resources>
        </build>
    </profile>
</profiles>

【问题讨论】:

  • 试试 **/data.sql**/schema.sql
  • 还是不行

标签: maven spring-boot spring-data spring-data-jpa


【解决方案1】:

Spring Boot 默认启用它并从标准位置 schema.sql 和 data.sql 加载 SQL。如果你想禁用它,你可以尝试,

spring.datasource.initialize=false

application.properties 中,或者如果您想更改默认方案或数据脚本位置,您可以使用,

spring.datasource.schema=
spring.datasource.data=

【讨论】:

  • 嗨@mrt 我尝试了你的解决方案,我得到一个错误 [/../../../sql/schema.sql] 已被规范化为 [null] 这是无效的。
【解决方案2】:

你可以在你的测试方法上写这个注解

@TestPropertySource(locations = "classpath:application-test.properties")

你的 application-test.properties 应该有这样的东西

spring.datasource.data=classpath:/database/seed.sql

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 2019-08-12
    • 2018-02-17
    • 2022-01-08
    • 2021-10-06
    相关资源
    最近更新 更多