Flowable 快速入门教程:SpringBoot 集成 Flowable + Flowable Modeler 导致自身 XML 扫描不到解决方案
前言
本文承接:Flowable 快速入门教程:SpringBoot 集成 Flowable + Flowable Modeler 流程配置可视化(超详细)
建议:流程引擎与业务代码分开成两个分开,如果一定要再流程引擎项目中写自己的代码,发现自己 xml 扫描不到,请往下看。
手动创建 DataSource Bean
如果缺少 DataSourceBean,可以选择手动创建
新建 DatabaseAutoConfiguration.java
把 DatabaseConfiguration.java
文件中的 liquibase
这个方法复制到自己这,这个是进行数据表转换的部分。
xml 扫描不到是因为,之前是 Flowable
创建的 SqlSessionFactory
,DatabaseConfiguration
是在 jar 包里,因此扫描不到自己项目包下的 xml,于是改为我们自行创建 SqlSessionFactory
。
DatabaseAutoConfiguration.java
@Configuration
public class DatabaseAutoConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseAutoConfiguration.class);
protected static final String LIQUIBASE_CHANGELOG_PREFIX = "ACT_DE_";
@Bean
public Liquibase liquibase(DataSource dataSource) {
LOGGER.info("Configuring Liquibase");
Liquibase liquibase = null;
try {
DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
database.setDatabaseChangeLogTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
database.setDatabaseChangeLogLockTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());
liquibase = new Liquibase("META-INF/liquibase/flowable-modeler-app-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
liquibase.update("flowable");
return liquibase;
} catch (Exception e) {
throw new InternalServerErrorException("Error creating liquibase database", e);
} finally {
closeDatabase(liquibase);
}
}
private void closeDatabase(Liquibase liquibase) {
if (liquibase != null) {
Database database = liquibase.getDatabase();
if (database != null) {
try {
database.close();
} catch (DatabaseException e) {
LOGGER.warn("Error closing database", e);
}
}
}
}
}
配置修改
mybatis:
# 新增 modeler-mybatis-mappings xml 扫描
mapper-locations: mapper/*/*.xml, classpath*:mapper/*.xml, classpath:/META-INF/modeler-mybatis-mappings/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 参数配置
configuration-properties:
# 配置流程引擎参数,详情可见 DatabaseConfiguration
blobType: BLOB
boolValue: TRUE
# 不要设置库名,否则会出现双库名 bug
prefix: ''
启动器修改
把引用的 DatabaseConfiguration
改为 DatabaseAutoConfiguration
@Import(value={
// 引入修改的配置
ApplicationConfiguration.class,
AppDispatcherServletConfiguration.class,
// 引入 DatabaseConfiguration 表更新转换
// DatabaseConfiguration.class,
// 引入 DatabaseAutoConfiguration 表更新转换
DatabaseAutoConfiguration.class})
// 开启注册中心
@EnableDiscoveryClient
@ComponentScan(basePackages = {"com.springcloud.*"})
@MapperScan("com.springcloud.*.dao")
@SpringBootApplication(exclude={SecurityAutoConfiguration.class})
public class FlowableApplication {
public static void main(String[] args) {
SpringApplication.run(FlowableApplication.class, args);
}
}
效果
表更新
调用自己的接口
调用流程引擎接口
结尾
参考项目:https://gitee.com/linjinp-spring-cloud/linjinp-spring-cloud
文件位置:
DatabaseAutoConfiguration.java:flowable-demo 模块下的 flowable.conf 包下
接口:flowable-demo 模块下的 flowable.api 包下