使用 liquibase 和 springboot ,创建了数据库更改日志并能够使用 maven-liquibase-plugin (mvn liquibase:update) 成功运行它。我正在编写集成测试,其中需要以编程方式创建 liquibase 更改。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DummyApplication.class)
@ActiveProfiles("test")
public class TestDummyService
{
@Autowired
private SpringLiquibase springLiquibase;
...
@Test
public void testDummyRequest()
{
try {
Connection connection = springLiquibase.getDataSource().getConnection();
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
Liquibase liquibase = new liquibase.Liquibase("liquibase/changelog/db-changelog-master.xml", new ClassLoaderResourceAccessor(), database);
liquibase.update(new Contexts(springLiquibase.getContexts()), new LabelExpression(springLiquibase.getLabels()));
} catch (LiquibaseException | SQLException e) {
e.printStackTrace();
}
}
运行上述测试时出现以下异常。
java.lang.IllegalStateException:无法在 org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext 加载 ApplicationContext(DefaultCacheAwareContextLoaderDelegate.java:125)
原因:org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class] 中定义名称为“liquibase”的 bean 创建错误:通过工厂方法进行 Bean 实例化失败; 嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [liquibase.integration.spring.SpringLiquibase]:工厂方法“liquibase”抛出异常;嵌套异常是 java.lang.NoSuchMethodError: liquibase.integration.spring.SpringLiquibase.setLiquibaseSchema(Ljava/lang/String;)V
引起:java.lang.NoSuchMethodError: liquibase.integration.spring.SpringLiquibase.setLiquibaseSchema(Ljava/lang/String;)
莫回无
相关分类