sprint boot ,maven 項目 flyway 使用

添加maven 依賴java

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
    <version>5.0.3</version>
</dependency>
<plugin>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>5.0.3</version>
</plugin>

在項目路徑下建立 db/migrationweb

/db/migrationspring

sql 裏面是建立數據庫建表,加入數據 等sql

可是提示報錯數據庫

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
 apache

/db/migration 的位置問題api

改到項目下就能夠了maven

但仍然報錯ui

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Wrong migration name format: V1_initial.sql(It should look like this: V1.2__Description.sql)this

注意格式 :V1.2__Description.sql 

 

修改後又有新的報錯

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Found non-empty schema(s) `test` without schema history table! Use baseline() or set baselineOnMigrate to true to initialize the schema history table.

非空的數據庫是不會執行,提示沒有flyway 版本的表,初始化須要空的數據庫
 

繼續報錯

===2019-09-19 16:08:34.078 INFO  org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory Line:44  - Creating Schema History table: `test`.`flyway_schema_history`
===2019-09-19 16:08:43.241 WARN  org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext Line:558 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.sqlscript.FlywaySqlScriptException: 
Script failed

-------------
SQL State  : null
Error Code : 0
Message    : sql injection violation, comment not allow : CREATE TABLE `test`.`flyway_schema_history` (
    `installed_rank` INT NOT NULL,
    `version` VARCHAR(50),
    `description` VARCHAR(200) NOT NULL,
    `type` VARCHAR(20) NOT NULL,
    `script` VARCHAR(1000) NOT NULL,
    `checksum` INT,
    `installed_by` VARCHAR(100) NOT NULL,
    `installed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `execution_time` INT NOT NULL,
    `success` BOOL NOT NULL,
    -- Add the primary key as part of the CREATE TABLE statement in case `innodb_force_primary_key` is enabled
    CONSTRAINT `flyway_schema_history_pk`PRIMARY KEY (`installed_rank`)
) ENGINE=InnoDB
Line       : 17

.

.

.

===2019-09-19 16:08:43.241 INFO  org.springframework.jmx.export.annotation.AnnotationMBeanExporter Line:451 - Unregistering JMX-exposed beans on shutdown
===2019-09-19 16:08:43.257 INFO  com.alibaba.druid.pool.DruidDataSource Line:1825 - {dataSource-1} closed
===2019-09-19 16:08:43.257 INFO  org.springframework.cache.ehcache.EhCacheManagerFactoryBean Line:192 - Shutting down EhCache CacheManager
===2019-09-19 16:08:43.288 INFO  org.apache.catalina.core.StandardService Line:180 - Stopping service [Tomcat]
===2019-09-19 16:08:43.304 INFO  org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener Line:101 - 

sql 是能夠執行建立表的

由於在數據源配置時,加上了 Druid 的 wall 過濾器。而它默認的攔截策略是,不容許 SQL 中帶有備註。

手工優先建立表再啓動項目

沒毛病啓動成功

相關文章
相關標籤/搜索