添加graphql解析器时,Flyway迁移停止工作
我在尝试用Flyway、H2和GraphQL编写Java应用程序时遇到了一个问题 添加GraphQL Reslover后,不会执行/可见Flyway迁移。 这个简单的库示例将说明这个问题 基本图书实体添加graphql解析器时,Flyway迁移停止工作,graphql,h2,flyway,Graphql,H2,Flyway,我在尝试用Flyway、H2和GraphQL编写Java应用程序时遇到了一个问题 添加GraphQL Reslover后,不会执行/可见Flyway迁移。 这个简单的库示例将说明这个问题 基本图书实体 @Data @Entity @Table(name = "books") public class BookEntity { @Id @GeneratedValue(generator = "system-uuid") @Gener
@Data
@Entity
@Table(name = "books")
public class BookEntity {
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "id", updatable = false, nullable = false)
String id;
@Column(name = "title")
String title;
@Column(name = "author")
String author;
}
经典的SpringREST应用程序,带有简单的BookController和图书存储库
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
到目前为止一切正常,flyway迁移文件填充了数据库,我可以使用RESTAPI查询数据。接下来,开始定义graphql模式
type Query {
books: [Book]
}
应用程序已编译,数据库已填充,REST Api正在运行。
当我为grahpQL添加BookResolver时,问题开始出现:
@Component
@AllArgsConstructor
public class BookResolver implements GraphQLQueryResolver {
private final BookRepository bookRepository;
public Collection<BookEntity> books() {
return bookRepository.findAll();
}
}
检查h2控制台还显示缺少该表
有谁能告诉我发生了什么,定义BookResolver会使表从H2数据库中消失
application.yaml和pom.xml:
h2-db-url: jdbc:h2:mem:testdb;MODE=MySQL
spring:
datasource:
url: ${h2-db-url}
jpa:
open-in-view: false
hibernate:
ddl-auto: none
h2:
console:
enabled: true
path: /h2
flyway:
url: ${h2-db-url}
locations: classpath:db/migration
4.0.0
org.springframework.boot
spring启动程序父级
2.4.4
com.example.library
erko后端
0.0.1-快照
书籍图形
书籍图形
14
11.0.0
org.springframework.boot
spring引导启动器数据jpa
org.springframework.boot
SpringBootStarterWeb
com.graphql-java-kickstart
graphql弹簧启动机
${graphql spring boot starter.version}
org.flywaydb
飞道核心
com.h2数据库
氢
运行时
org.projectlombok
龙目
真的
org.springframework.boot
弹簧起动试验
测试
org.springframework.boot
springbootmaven插件
org.projectlombok
龙目
INSERT INTO books (id, title, author)
VALUES ('0c458702-5a1e-4e74-9e74-7ab02dbd4bff', 'A Brief History of Time', 'Stephen Hawking'),
('4b433113-7999-4e71-a89b-b90ada49d87f', 'Surely You’re Joking, Mr Feynman!', 'Richard Feynman'),
('366d98d7-6724-4507-9797-e43bec6ab407', 'Pale Blue Dot', 'Carl Sagan'),
('d99be00f-894c-47bc-8661-d4eda9447b19', 'Astrophysics for People in a Hurry', 'Neil deGrasse Tyson');
type Query {
books: [Book]
}
type Book {
id: ID,
title: String,
author: String
}
@Component
@AllArgsConstructor
public class BookResolver implements GraphQLQueryResolver {
private final BookRepository bookRepository;
public Collection<BookEntity> books() {
return bookRepository.findAll();
}
}
Creating Schema History table "PUBLIC"."flyway_schema_history" ...
Current version of schema "PUBLIC": << Empty Schema >>
Migrating schema "PUBLIC" to version "1.0 - init-schema"
Migrating schema "PUBLIC" to version "1.1 - instert-data"
Successfully applied 2 migrations to schema "PUBLIC" (execution time 00:00.034s)
Table "BOOKS" not found; SQL statement:
h2-db-url: jdbc:h2:mem:testdb;MODE=MySQL
spring:
datasource:
url: ${h2-db-url}
jpa:
open-in-view: false
hibernate:
ddl-auto: none
h2:
console:
enabled: true
path: /h2
flyway:
url: ${h2-db-url}
locations: classpath:db/migration
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.library</groupId>
<artifactId>erko-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>book-graphql</name>
<description>book-graphql</description>
<properties>
<java.version>14</java.version>
<graphql-spring-boot-starter.version>11.0.0</graphql-spring-boot-starter.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>${graphql-spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>