[spring batch]自动创建表

本文介绍了如何在Spring Boot应用中使用Spring Batch自动在数据库中创建必要的表。通过设置`spring.batch.initialize-schema=always`,可以确保Spring Batch在运行时初始化数据库 schema。相关SQL脚本可以在`spring-batch-core`的jar包中找到,如`schema-mysql.sql`。注意`spring.batch.schema`配置不接受逗号或空格作为路径分隔符。
摘要由CSDN通过智能技术生成
#spring.batch.initializer.enabled=true
spring.batch.initialize-schema=ALWAYS
  • 看.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.1.6.RELEASE/spring-boot-autoconfigure-2.1.6.RELEASE.jar!/META-INF/spring-configuration-metadata.json
    {
      "name": "spring.batch.initializer.enabled",
      "type": "java.lang.Boolean",
      "description": "Create the required batch tables on startup if necessary. Enabled automatically\n if no custom table prefix is set or if a custom schema is configured.",
      "deprecated": true,
      "deprecation": {
        "level": "error",
        "replacement": "spring.batch.initialize-schema"
      }
    },
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring MyBatis自动创建表是指在使用Spring MyBatis框架时,可以通过配置文件的设置来实现数据库表的自动创建。在使用MyBatis框架时,我们需要在数据库中手动创建相应的表,但是对于一些新项目中表较多的情况下,手动创建表比较耗时,而且容易产生错误。而使用Spring MyBatis框架自动创建表则可以节省大量的时间和精力,并且减少了错误的产生。 具体实现是在Spring配置文件(比如 applicationContext.xml)中使用自动创建表的配置,如下所示: ``` <!-- 自动创建表 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis-config.xml" /> <property name="mapperLocations" value="classpath*:mybatis/mapper/*.xml" /> <!-- 自动创建表 --> <property name="configuration"> <bean class="org.apache.ibatis.session.Configuration"> <property name="mapUnderscoreToCamelCase" value="true" /> <property name="useGeneratedKeys" value="true" /> <property name="defaultExecutorType" value="REUSE" /> <property name="defaultStatementTimeout" value="25000" /> <property name="autoMappingBehavior" value="FULL" /> <property name="autoMappingUnknownColumnBehavior" value="WARNING" /> <property name="cacheEnabled" value="true" /> <!-- 自动创建表 --> <property name="useGeneratedKeys" value="true" /> <property name="useColumnLabel" value="true" /> <property name="jdbcTypeForNull" value="NULL" /> <property name="defaultFetchSize" value="1000" /> <property name="defaultExecutorType" value="BATCH" /> <property name="logImpl" value="LOG4J" /> <property name="autoMappingBehavior" value="PARTIAL" /> <property name="autoMappingUnknownColumnBehavior" value="WARNING" /> </bean> </property> </bean> ``` 其中,配置文件中的`<property name="useGeneratedKeys" value="true" />`和`<property name="useColumnLabel" value="true" />`可以实现自动创建表的功能。 需要注意的是,在使用自动创建表的功能时,我们需要保证配置文件的正确性,否则会导致程序运行出错。同时,在使用自动创建表的功能时,需要注意数据库表的命名规范,以及需要自己编写好实体类和MyBatis的Mapper文件,以确保程序可以正常运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值