Issue
I have multimodule project using Spring Boot and liquibase. If i run it usring mvn spring-boot:run it works, but if i run it using intellej i get this error:
2022-07-15 14:22:36 ERROR 6908 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [liquibase.integration.spring.SpringLiquibase]: Factory method 'liquibase' threw exception; nested exception is java.lang.NoClassDefFoundError: liquibase/Scope
at [email protected]/org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
at [email protected]/org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
at [email protected]/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
at [email protected]/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
at [email protected]/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at [email protected]/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at [email protected]/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at [email protected]/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at [email protected]/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at [email protected]/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at [email protected]/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at [email protected]/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at [email protected]/org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154)
at [email protected]/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908)
at [email protected]/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at [email protected]/org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66)
at [email protected]/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
at [email protected]/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at [email protected]/org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at [email protected]/org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at [email protected]/org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at package/module1.Application.main(Application.java:23)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [liquibase.integration.spring.SpringLiquibase]: Factory method 'liquibase' threw exception; nested exception is java.lang.NoClassDefFoundError: liquibase/Scope
at [email protected]/org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at [email protected]/org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
... 21 common frames omitted
Caused by: java.lang.NoClassDefFoundError: liquibase/Scope
at liquibase.integration.spring.SpringLiquibase.<init>(SpringLiquibase.java:56)
at [email protected]/org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase.<init>(DataSourceClosingSpringLiquibase.java:36)
at [email protected]/org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration.createSpringLiquibase(LiquibaseAutoConfiguration.java:113)
at [email protected]/org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration.liquibase(LiquibaseAutoConfiguration.java:90)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at [email protected]/org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 22 common frames omitted
Caused by: java.lang.ClassNotFoundException: liquibase.Scope
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 29 common frames omitted
Process finished with exit code 1
Module info of my module:
open module module1 {
requires spring.boot;
requires spring.cloud.commons;
requires spring.boot.autoconfigure;
requires lombok;
requires spring.context;
requires spring.core;
requires org.slf4j;
requires spring.data.jpa;
requires org.apache.logging.slf4j;
requires spring.web;
requires com.fasterxml.jackson.annotation;
requires spring.cloud.openfeign.core;
requires org.bouncycastle.provider;
requires org.apache.commons.codec;
requires io.netty.handler;
requires java.transaction;
requires spring.beans;;
}
Any ideas how to fix it? I will aprecciate it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Solution
My guess is that your Liquibase files are in a folder named liquibase
. Rename it to something else like liquibase-migration-files
or equivalent, but definitely different from just liquibase
.
My interpretation is that having a liquibase
folder make the ClassLoader think the package liquibase
is declared in the module where your Liquibase configuration is stored, thus the ClassLoader doesn't try to look in the unnamed module where the Liquibase library is located.
Answered By - Vincz777
Answer Checked By - Clifford M. (JavaFixing Volunteer)