【发布时间】:2015-07-12 21:12:48
【问题描述】:
我正在尝试设置我的 spring boot 应用程序,该应用程序使用 jdbcAuthentication 和 spring 安全文档附录中提供的默认数据库方案对其用户进行身份验证。但是我在数据库初始化期间遇到了这个异常:
org.flywaydb.core.api.FlywayException:发现没有元数据表的非空模式“PUBLIC”!使用 baseline() 或将 baselineOnMigrate 设置为 true 来初始化元数据表。
身份验证管理器的配置如下:
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic()
.realmName("shipment2rss")
.and()
.logout()
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.jdbcAuthentication()
.dataSource(dataSource)
.withDefaultSchema();
}
}
我已经读到问题接缝是在 Flyway 相关代码执行之前调用了方法 configureGlobal(AuthenticationManagerBuilder )(请参阅 How to use Flyway in Spring Boot with JDBC Security?),但没有找到解决此特定问题的分步指南.
谁能给我这样的指南或指向一个网站?
编辑我在github上传了一个项目来显示问题:https://github.com/smilingj/springboot-authentication-flyway-sample/tree/e48ce63568776d99e49a9548d8362168cc3a3367
【问题讨论】:
-
扩展
FlywayMigrationStrategy并在调用超级方法之前执行错误消息告诉您的操作(将baselineOnMigrate设置为true)。扩展后将其注册为 bean。但是最好让 FlyWay 完成所有工作,因此删除withDefaultSchema()并将用于创建安全模式的 sql 添加到 flyway。 -
感谢您的回复。我没有意识到调用
withDefaultSchema()会尝试初始化数据库。我删除了该声明,它就像一个魅力。根本不需要扩展FlywayMigrationStrategy。我更新了 github 项目以显示解决方案:github.com/smilingj/springboot-authentication-flyway-sample/…。我想将您的答案标记为正确,但这需要一个答案。
标签: java spring-security spring-boot flyway