Custom Bean deployment for Task/Rest App

I want to use an expression in my process which uses a spring bean method for evaluation. From what I understand the flowable apps are now spring boot apps. Therefore I need to create a bean in a classpath where the bean will be picked up from. Is that correct and if so what are the classpaths I should use for the task and rest apps. Is there an example of a simple custom bean that demonstrates this. Lastly, if I wanted to include a bean through xml configuration (as in the camel task example), where do I put the xml?

Many thanks for your answer. I am not used to Spring Boot so really feel like I am flailing around in the dark here.

Brian

Hey Brian,

You can use the fact that the Flowable apps are now Spring Boot apps and you can create your own auto configuration jar with the required logic. You can then put the jar in the classpath of the servlet container you are using (in case this is tomcat in the tomcat libs folder).

What you can do is to create a jar only with you need add a META-INF/spring.factories file in your jar and in it put:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  com.your.own.package.YourOwnCustomConfiguration

YourOwnCustomConfiguration would be a normal Spring configuration. In that configuration you can create the bean in a normal way. For example:

@Configuration
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
@ConditionalOnBean(ProcessEngine.class)
public class YourOwnConfiguration {

    @Bean
    public CustomBean customBean() {
        // create your bean
    }
}

With @AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE) your auto configuration would be scanned last. With @ConditionalOnBean(ProcessEngine.class) your auto configuration would be triggered only if the ProcessEngine bean is present.

In case you want to use XML for your configuration you can still create it in a similar fashion.

@Configuration
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
@ConditionalOnBean(ProcessEngine.class)
public class YourOwnConfiguration {

    @Configuration
    @ImportResource("path-to-your.xml")
    public static class XmlImportResourceConfiguration {
        // This class is needed in order to conditionally import the xml (i.e. when the ProcessEngine bean is present)
    }

    @Bean
    public CustomBean customBean() {
        // create your bean
    }
}

NB: In case you need extra dependencies you will need to provide them as well.

Cheers,
Filip

1 Like