我正在尝试用spring boot编写我的第一个spring批处理示例。我想在应用程序启动后立即在mysql中创建数据库。
我在pom中具有以下依赖性
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.spring</groupId>
<artifactId>hello-world</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>helloWorld</name>
<description>Hello World for Spring Batch</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
和application.properties具有以下配置
spring.datasource.url=jdbc:mysql://localhost:3306/batchjob?allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.username=root
spring.datasource.password= abcd1234
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.schema=schema-mysql.sql
spring.batch.initialize-schema=always
但是当我启动应用程序时,它无法识别Mysql,并且在日志中它正在打印
2019-03-10 14:32:01.381 INFO 48560 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: HSQL
我缺少什么将在mySql中启用自动模式创建?
答案 0 :(得分:0)
您应该添加此内容:
答案 1 :(得分:0)
DDL脚本位于org.springframework.batch.core
包中,因此您的spring.datasource.schema
应该是:
spring.datasource.schema=org/springframework/batch/core/schema-mysql.sql
您甚至可以忽略此属性,因为它将从您的数据源中自动检测到。