I am trying to integrate flyway for mongoDB with springboot with manual configuation but facing the the below issue:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception with message: 'void sun.misc.Unsafe.ensureClassInitialized(java.lang.Class)'
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:177) ~[spring-beans-6.1.10.jar:6.1.10]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644) ~[spring-beans-6.1.10.jar:6.1.10]
... 18 common frames omitted
Caused by: java.lang.NoSuchMethodError: 'void sun.misc.Unsafe.ensureClassInitialized(java.lang.Class)'
FlywayConfig file:
@Configuration
public class FlywayConfig {
@Bean
public Flyway flyway() {
Flyway flyway = Flyway.configure()
.dataSource("jdbc:mongodb://localhost:27017/vms", null, null)
.locations("classpath:db/migration")
.sqlMigrationSuffixes(".js")
.load();
// Execute Flyway migrations
flyway.migrate();
return flyway;
}
}
pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>flyway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>flyway</name>
<description>Flyway integration with mongoDB</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<exclusions>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>10.15.2</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-mongodb</artifactId>
<version>10.10.0</version>
</dependency>
<dependency>
<groupId>com.github.kornilova203</groupId>
<artifactId>mongo-jdbc-driver</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
application.yml file:
spring:
application:
name: flyway-tool
datasource:
url: jdbc:mongodb://localhost:27017/vms
user: ""
password: ""
driver-class-name: com.dbschema.MongoJdbcDriver
# flyway:
# enabled: false
# url: jdbc:mongodb://localhost:27017/vms
# user: ""
# password: ""
# driver-class-name: com.dbschema.MongoJdbcDriver
# environment: "mongodb"
# fail-on-missing-locations: true
# locations: classpath:db/migration
# sqlMigrationSuffixes:
# - ".js"
logging:
level:
org.flywaydb: DEBUG
The automatic config for flyway is not working that's why I have commented it out.
I am expecting the application to run successfully
I am trying to integrate flyway for mongoDB with springboot with manual configuation but facing the the below issue:
Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception with message: 'void sun.misc.Unsafe.ensureClassInitialized'
FlywayConfig file:
pom.xml file:
application.yml file:
The automatic config for flyway is not working that's why I have commented it out.
I am expecting the application to run successfully