Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 2.1.0 with Flyway 4.2.0

I would like to upgrade for my new projects to Spring Boot version 2.1.0, but I am limited with Oracle 11 database, which is supported by the Flyway 4.2.0 library. Everything runs normally on Spring Boot version 2.0.5 Release, but when moving to 2.1.0 release I get this error:

java.lang.NoClassDefFoundError:  org/flywaydb/core/api/configuration/FluentConfiguration 

The POM configuration is as follows:

<parent>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-parent</artifactId>     <version>2.1.0.RELEASE</version>     <relativePath/> <!-- lookup parent from repository --> </parent>  <properties>     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>     <java.version>1.8</java.version>     <ojdbc6.version>11.2.0.1</ojdbc6.version> </properties>  <dependencies>     <dependency>         <groupId>com.oracle.jdbc</groupId>         <artifactId>ojdbc6</artifactId>         <version>${ojdbc6.version}</version>     </dependency>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-web</artifactId>     </dependency>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-devtools</artifactId>         <scope>runtime</scope>     </dependency>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-data-jpa</artifactId>     </dependency>     <dependency>         <groupId>org.flywaydb</groupId>         <artifactId>flyway-core</artifactId>         <version>4.2.0</version>     </dependency> </dependencies> 

UPDATE

I am able to solve the problem via @Configuration (or of course add to the main class), but the thing is its a bug or feature? Prior to version 2.1.0 everything was done via autoconfiguration and it works out-of-box.

@Bean(initMethod = "migrate") Flyway flyway() {     Flyway flyway = new Flyway();     flyway.setBaselineOnMigrate(true);     flyway.setDataSource("jdbc:oracle:thin:@localhost:1521:xe", "USER", "PASSWORD1");     return flyway; } 
like image 830
troger19 Avatar asked Nov 16 '18 18:11

troger19


People also ask

Which version of Spring does spring boot 2.6 2 use?

Choosing a Spring version is relatively simple: If you are building new Spring Boot projects, the version of Spring you are using is already pre-defined for you. If you are using Spring Boot 2.7. x, for example, you will be using Spring 5.3.

What is the use of flyway in spring boot?

Spring boot flyway is application software of database migration which was used to migrate, validate, undo, clean, repair, and baseline commands of SQL. Flyway framework is basically used to update the database version using migration tools.

Which version of Spring is compatible with Spring boot?

System Requirements. Spring Boot 2.7. 4 requires Java 8 and is compatible up to and including Java 19. Spring Framework 5.3.


1 Answers

I had the same problem with PostgreSQL 9.2, and used the following class to solve the problem.

Be aware though that all the custom properties you might set in the Spring Boot properties will be ignored, since that replaces the whole Flyway autoconfiguration by your own. So you might have to add some additional code to fit your needs.

@Configuration class FlywayConfig {     @Bean     fun flyway(dataSource: DataSource): Flyway {         val flyway = Flyway()         flyway.dataSource = dataSource         return flyway     }      @Bean     fun flywayInitializer(flyway: Flyway): FlywayMigrationInitializer {         return FlywayMigrationInitializer(flyway, null)     }      /**      * Additional configuration to ensure that [EntityManagerFactory] beans depend on the      * `flywayInitializer` bean.      */     @Configuration     class FlywayInitializerJpaDependencyConfiguration : EntityManagerFactoryDependsOnPostProcessor("flywayInitializer") } 

PS: this is Kotlin code, but you should be able to translate it to Java fairly easily.

like image 52
JB Nizet Avatar answered Sep 22 '22 06:09

JB Nizet