使用 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;)
如何使用 springboot 和 liquibase 在內存數據庫中
慕婉清6462132
2022-07-06 15:55:02