Hello,
I have installed flowable using springboot and it gives the following error:
Consider defining a bean of type 'org.flowable.engine.IdentityService' in your configuration.
My main class: package com.example.flowable_app;
import org.flowable.engine.IdentityService;
import org.flowable.idm.api.Group;
import org.flowable.idm.api.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class FlowableAppApplication {
private static final Logger logger = LoggerFactory.getLogger(FlowableAppApplication.class);
public static void main(String[] args) {
SpringApplication.run(FlowableAppApplication.class, args);
}
@Bean
public CommandLineRunner initUsersAndGroups(IdentityService identityService) {
return args -> {
try {
// Check if any users exist to avoid re-initialization
if (identityService.createUserQuery().count() == 0) {
logger.info("Initializing users and groups...");
// Create Groups
createGroupIfNotExists(identityService, "employees", "Employees");
createGroupIfNotExists(identityService, "supervisors", "Supervisors");
createGroupIfNotExists(identityService, "hrs", "HRs");
createGroupIfNotExists(identityService, "finances", "Finances");
// Create Users and Assign to Groups
createUserAndAssignGroup(identityService, "employee", "password", "employees");
createUserAndAssignGroup(identityService, "supervisor", "password", "supervisors");
createUserAndAssignGroup(identityService, "hr", "password", "hrs");
createUserAndAssignGroup(identityService, "finance", "password", "finances");
// Admin User for REST API Access (no group assignment)
createUserAndAssignGroup(identityService, "admin", "test", null);
logger.info("Users and groups initialized successfully.");
} else {
logger.info("Users already exist, skipping initialization.");
}
} catch (Exception e) {
logger.error("Failed to initialize users and groups: {}", e.getMessage(), e);
throw new RuntimeException("Initialization of users and groups failed", e);
}
};
}
private void createGroupIfNotExists(IdentityService identityService, String id, String name) {
Group existingGroup = identityService.createGroupQuery().groupId(id).singleResult();
if (existingGroup == null) {
Group group = identityService.newGroup(id);
group.setName(name);
group.setType("security-role");
identityService.saveGroup(group);
logger.info("Created group: {} ({})", name, id);
} else {
logger.debug("Group {} ({}) already exists", name, id);
}
}
private void createUserAndAssignGroup(IdentityService identityService, String username, String password, String groupId) {
User existingUser = identityService.createUserQuery().userId(username).singleResult();
if (existingUser == null) {
User user = identityService.newUser(username);
user.setPassword(password); // Flowable hashes the password
identityService.saveUser(user);
logger.info("Created user: {}", username);
} else {
logger.debug("User {} already exists", username);
}
if (groupId != null) {
long membershipCount = identityService.createGroupQuery()
.groupId(groupId)
.groupMember(username)
.count();
if (membershipCount == 0) {
identityService.createMembership(username, groupId);
logger.info("Assigned user {} to group {}", username, groupId);
} else {
logger.debug("User {} is already a member of group {}", username, groupId);
}
}
}
}
my pom: <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>flowable-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>flowable-app</name>
<description>Demo project for Flowable using Springboot</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
<flowable.version>7.2.0</flowable.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Flowable Starters -->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter-process-rest</artifactId>
<version>${flowable.version}</version>
</dependency>
<!-- Spring Security for Basic Auth -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- HTTP Client for Spring Boot App -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter-process</artifactId>
<version>${flowable.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>central</id>
<url></url>
</repository>
<repository>
<id>flowable</id>
<url>https://maven.flowable.org/releases</url>
</repository>
</repositories>
</project>
my application.properties
spring.application.name=flowable-app
logging.level.org.springframework.boot=DEBUG
spring.datasource.url=jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.sql.init.enabled=true
flowable.idm.enabled=true
flowable.process.enabled=true
flowable.rest-api-enabled=true
spring.jpa.hibernate.ddl-auto=none
flowable.database-schema-update=true
server.port=8080
flowable.idm.app.admin.user-id=admin
flowable.idm.app.admin.password=test
flowable.idm.app.admin.first-name=Admin
flowable.idm.app.admin.last-name=Admin
flowable.idm.app.admin.email=admin@flowable.org
flowable.database-schema-update Ascertain
logging.level.org.flowable=DEBUG