在Spring应用程序启动时加载sql脚本

时间:2017-09-14 21:36:08

标签: spring spring-boot

我有一个带有insert命令的sql脚本,我想在spring应用程序启动时用该脚本加载数据库中的数据。我怎么能这样做?

我的application.yml

datasource:
    url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false
    name:
    username: root
    password: root
    hikari:
        data-source-properties:
            cachePrepStmts: true
            prepStmtCacheSize: 250
            prepStmtCacheSqlLimit: 2048
            useServerPrepStmts: true
jpa:
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    database: MYSQL
    show-sql: true
    properties:
        hibernate.cache.use_second_level_cache: true
        hibernate.cache.use_query_cache: false
        hibernate.generate_statistics: true
        hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory

我在data.sql中声明了src/main/resources/data.sql,但数据在运行时没有加载到数据库中,应用程序日志也没有给出任何错误。

0 个答案:

没有答案
相关问题