小编xar*_*rqt的帖子

使用 Spring Boot 的 Flyway Core 给出错误 'delayedFlywayInitializer' 和 'entityManagerFactory' 之间的循环依赖关系

我想在 SQL Server 数据库上导入一些数据,我使用的是 Spring Boot 2.3.4。我还使用 Hibernate 来生成表。

我在pom中添加了flyway核心:

 <dependency>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-core</artifactId>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

创建了配置文件:

import org.flywaydb.core.Flyway;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
public class FlyWayConfiguration {

    @Bean
    FlywayMigrationInitializer flywayInitializer(Flyway flyway) {
        return new FlywayMigrationInitializer(flyway, (f) ->{} );
    }
    
    @Bean
    @DependsOn("entityManagerFactory")
    FlywayMigrationInitializer delayedFlywayInitializer(Flyway flyway) {
        return new FlywayMigrationInitializer(flyway, new FlywayMigrationStrategy() {
            @Override
            public void migrate(Flyway flyway) {
            
                flyway.migrate();
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个文件resources/db/migration/V1_0_1__InitialData.sql

现在我遇到了这个错误

    Error creating bean with name 'delayedFlywayInitializer' defined in class path …
Run Code Online (Sandbox Code Playgroud)

database sql-server spring flyway spring-boot

11
推荐指数
1
解决办法
8997
查看次数

在拦截器 Spring Boot 上添加自定义标头

我有一个拦截器,我需要添加代码其他部分所需的自定义标头

public class KeyTaskInterceptor implements HandlerInterceptor {

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {

    if (// a custom condition) {
        request.  // set custom header key ... `KeyCode`
    }
    return true;
} 
Run Code Online (Sandbox Code Playgroud)

问题是前端不会发送名为“ KeyCode”的自定义标头,并且我无法更改期望此标头的控制器的实现,因此我必须找到一种方法,在发送之前根据 preHandle 方法的请求添加自定义标头向控制器发出请求。有人能帮助我吗?

java spring jvm controller spring-boot

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

spring ×2

spring-boot ×2

controller ×1

database ×1

flyway ×1

java ×1

jvm ×1

sql-server ×1