我必须将Liquibase添加到正在运行的应用程序中。
我正在使用Spring 4和Liquibase 3.2.2。
在我的ApplicationContext中定义SpringLiquibase Bean后,我在服务器启动时收到以下错误:
Error creating bean with name 'liquiBase' defined in ... .webapp.configuration.ApplicationConfig: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Cannot resolve ServletContextResource without ServletContext
我的配置如下:
@Bean
public SpringLiquibase liquiBase(){
SpringLiquibase liquiBase = new SpringLiquibase();
liquiBase.setChangeLog(DATABASE_CHANGELOG_PATH);
liquiBase.setContexts("test, production");
liquiBase.setDataSource(dataSource());
return liquiBase;
}
我的WebAppInitilazier:
@Override
public void onStartup(ServletContext container) {
container.getServletRegistration("default").addMapping("/*");
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(ApplicationConfig.class);
rootContext.refresh();
container.addListener(new ContextLoaderListener(rootContext));
AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
webContext.register(RestServletContextConfiguration.class);
ServletRegistration.Dynamic dispatcher = container.addServlet(
"springRestDispatcher", new DispatcherServlet(webContext));
dispatcher.setMultipartConfig(new MultipartConfigElement(null,
20_971_520L, 41_943_040L, 512_000));
dispatcher.addMapping("/*");
}
我搜索过类似的问题,但遗憾的是没找到。 我的应用程序在没有liquibase定义的情况下正常工作。