好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

SpringBoot启动时自动执行sql脚本的方法步骤

需要配置项目下的yml文件:
在文件下加如如下配置:

?

1

2

data: classpath:code-generator-data.sql

initialization-mode: always

spring.datasource.initialization-mode:
初始化模式(springboot2.0),其中有三个值:
always为始终执行初始化
embedded只初始化内存数据库(默认值),如h2等
never为不执行初始化

spring.datasource.data:
数据初始化,默认加载data.sql,还会加载data-${platform}.sql文件,也可以指定文件,一般放在resources文件夹下,然后使用

classpath:文件.sql 指定 DQL(数据查询)脚本或DML(数据操作)脚本 文件, 一般都是数据插入脚本文件

yml:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

spring:

   datasource:

     driver-class-name: org.postgresql.Driver

     url: jdbc:postgresql://localhost:5432/are_code_generator

     username: postgres

     password: 123456

     data: classpath:code-generator-data.sql

     initialization-mode: always

   #    url: jdbc:mysql://192.168.70.38:4307/are_oms_tankInfo?useUnicode=true&characterEncoding=utf-8&useSSL=false

   #    username: root

   #    password: 123456

   jackson:

     time-zone: GMT+8

   jpa:

     properties:

       open-in-view: true

       hibernate:

         show_sql: true

         format_sql: true

         dialect: org.hibernate.dialect.PostgreSQLDialect

         temp:

           use_jdbc_metadata_defaults: false

         hbm2ddl:

           auto: update

     database: postgresql

   rabbitmq:

     host: 192.168.90.230

     port: 5672

     username: vxsip

     password: vxsip

     virtual-host: /

service:

   employee:

     staff: http://192.168.90.230/msc/are-basic/v1/sys/organization/staffs

     moudleAccountUrl: http://192.168.90.230/msc/are-basic/v1/login/account

到此这篇关于SpringBoot启动时自动执行sql脚本的方法步骤的文章就介绍到这了,更多相关SpringBoot自动执行sql脚本内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持! 

原文链接:https://blog.csdn.net/qq_39898191/article/details/110273650

查看更多关于SpringBoot启动时自动执行sql脚本的方法步骤的详细内容...

  阅读:42次