Run code after database creation in spring boot

Hello,

for setting up default permissions I am creating and saving authorizations in the postInit-Method of the SpringBootProcessEnginePlugin:

public class MyProcessEngineConfiguration extends AbstractCamundaConfiguration implements CamundaProcessEngineConfiguration {
    private final Logger logger = getLogger(WebAppSecurityConfig.class.getName());


    @Override
    public void postInit(SpringProcessEngineConfiguration configuration) {

// lines omitted

        setupPermissions(configuration.getAuthorizationService());
    }

This works if the database has already been created. But during the first startup in a test run, the database tables are not yet created when postInit method runs and setupPermissions fails.

Is it possible to run code after the database tables have been created?

regards
Dierk

The way to do something like that is to jump into the ProcessEngine’s lifecylce creation, instead of Spring’s. To do so, create a ProcessEnginePlugin implementation and add your initialisation to the postProcessEngineBuild method that passes you the engine that was built (the others give you the configuration). At that point you’re gauranteed that not only the tables are in place, but you can use the ProcessEngine’s services to work with them.

2 Likes

Thanks for the hint. I have implemented a ProcessEnginePlugin like this and it works now.

@Component
public class SetupDefaultPermissionsPlugin extends AbstractProcessEnginePlugin {

    @Override
    public void postProcessEngineBuild(ProcessEngine processEngine) {
        setupPermissions(processEngine.getAuthorizationService());
    }

[setupPermissions: code omitted]
1 Like

Great! Happy to see that worked out :slight_smile: