我想在 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) 我有一个拦截器,我需要添加代码其他部分所需的自定义标头
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 方法的请求添加自定义标头向控制器发出请求。有人能帮助我吗?