如何在具有JDBC安全性的Spring Boot中使用Flyway? [英] How to use Flyway in Spring Boot with JDBC Security?

查看:84
本文介绍了如何在具有JDBC安全性的Spring Boot中使用Flyway?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Spring Boot项目中使用Flyway作为数据库迁移处理的首选方式(使用当前的V1.2.1.RELEASE).

I would like to use Flyway as preferred way of database migration handling in my Spring Boot project (using current V1.2.1.RELEASE).

到目前为止,这种方法工作正常,但是使用JDBC数据源与Spring Security的集成似乎覆盖了Flyway机制.

This is working fine so far however the integration with Spring Security using a JDBC DataSource seems to override the Flyway mechanism.

下面是简单的情况:

  • Spring Boot 1.2.1
  • PostgreSQL 9.4.1
  • 根据Spring Security文档为用户,组和权限提供的Flyway迁移脚本

问题: Flyway迁移脚本未按预期在启动时执行.

Problem: The Flyway migration scripts are not executed at startup as expected.

可能是因为:如果使用Spring Boot项目至少也在使用JPA,则似乎只有在启动时才执行Flyway.由于Spring Security是基于纯JDBC的,因此我尝试临时使用基于JDBC的数据库初始化方案,如有效的Spring Boot文档(第68.3章)中所述,但是(如所记录的那样)这种方式类似于穷人方法"我真的很想对包含用户/组/权限信息的这些表也使用Flyway.

Maybe cause: It seems that Flyway is only executed at startup if the using Spring Boot project is also using JPA at least. Since Spring Security is based on plain JDBC, I've tried to temporary use the JDBC based database initialization scheme as described in Spring Boot docs (Chapter 68.3) which works, but (as documented) this way is like the 'poor man approach' and I'd really like to use Flyway also for these tables containing the User/Group/Authorities information.

推荐答案

好的,经过进一步调查,我发现了问题所在:

Ok, after some further investigation I've found the problem:

实际上,在标准的Spring Boot项目中,安全上下文是在进行任何基于Flyway的迁移之前初始化的.

Indeed, in a standard Spring Boot project the security context is initialized before any Flyway based migration takes place.

通常这不是一个大问题,但是我还使用了AuthenticationManagerBuilder来创建默认的admin用户.创建这样的初始用户帐户似乎是错误的方法.

Normally this is not a big issue, but I've also used the AuthenticationManagerBuilder for creating a default admin user. This seems to be the wrong approach for creating such an initial user account.

这篇关于如何在具有JDBC安全性的Spring Boot中使用Flyway?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆