简体   繁体   English

ff4j kotlin 无法创建表抛出 BadSqlGrammarException

[英]ff4j kotlin cannot create table throws BadSqlGrammarException

I am trying to integrate FF4J into my spring boot application project however it looks like there is some issue with driver or FF4J and the db schema is not created.我正在尝试将 FF4J 集成到我的 spring 启动应用程序项目中,但是看起来驱动程序或 FF4J 存在一些问题,并且未创建数据库架构。

My configuration file:我的配置文件:

@Configuration
@ConditionalOnClass(FF4j::class)
class FF4JConfiguration {

    @field:Value("\${spring.ff4j.datasource.url}")
    private lateinit var driverUrl: String

    @field:Value("\${spring.datasource.driver-class-name}")
    private lateinit var driverClass: String

    @field:Value("\${spring.datasource.username}")
    private lateinit var user: String

    @field:Value("\${spring.datasource.password}")
    private lateinit var password: String

    @Bean
    fun getFF4j(): FF4j {
        val source = MysqlDataSource()
        source.setURL(driverUrl)
        source.password = password
        source.user = user
        val fF4j = FF4j()
        fF4j.featureStore = FeatureStoreSpringJdbc().apply { setDataSource(source) }
        fF4j.propertiesStore = PropertyStoreSpringJdbc().apply { setDataSource(source) }
        fF4j.eventRepository = JdbcEventRepository(source)
        fF4j.audit(true)
        fF4j.autoCreate(true)
        return fF4j
    }
}

When I debug this is how the datasource looks like:当我调试时,这是数据源的样子: 在此处输入图像描述

but I do get this BadSqlGrammarException and I have no idea why it cannot create SQL tables for me in the database.但我确实得到了这个BadSqlGrammarException ,我不知道为什么它不能在数据库中为我创建 SQL 表。 The server is running and database is fine because I have other tables as well.服务器正在运行并且数据库很好,因为我还有其他表。

My build.gradle.kts我的 build.gradle.kts

    implementation("org.ff4j:ff4j-core:1.8.12")
    implementation("org.ff4j:ff4j-web:1.8.12")
    implementation("org.ff4j:ff4j-store-springjdbc:1.8.12")
    implementation("mysql:mysql-connector-java:8.0.30")

Any ideas why this happens?任何想法为什么会发生这种情况?

This is fine.这可以。 FF4J does not create schema automatically for you. FF4J 不会自动为您创建模式。 You have to create it yourself by doing so:您必须这样做自己创建它:

fF4j.featureStore = JdbcFeatureStore().apply {
     dataSource = source
     createSchema()
}
fF4j.propertiesStore = JdbcPropertyStore().apply {
     dataSource = source
     createSchema()
}
fF4j.eventRepository = JdbcEventRepository(source).apply { createSchema() }

and you will be good to go.你会对 go 很好。 Most likely the exception you got is because the ff4j_features table does not exist.您遇到的异常很可能是因为 ff4j_features 表不存在。 Now it will create the schema and all tables and features should working fine现在它将创建架构,所有表和功能都应该可以正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM