Flowable 6.6.0 应用指南 - 自定义bean部署

Flowable 6.6.0 用户指南相关文档下载


Flowable
《Flowable 6.6.0应用指南》

自定义bean部署(Custom bean deployment)

There are multiple ways of providing custom beans to the Flowable application.
有多种方法可以向Flowable应用程序提供自定义bean。

1.使用Spring Boot 自动配置(Using Spring Boot auto configuration)

The Flowable application is a Spring Boot 2 application. This means that normal Spring Boot auto configuration can be used to make the beans to Flowable. This can be done in the following manner
Flowable应用程序是一个Spring Boot 2应用程序。这意味着可以使用正常的Spring Boot 自动配置来使bean可部署到Flowable。这可以通过以下方式完成

package com.your.own.package.configuration;

@Configuration
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE) // Makes sure that this configuration will be processed last by Spring Boot
@ConditionalOnBean(type = "org.flowable.engine.ProcessEngine") // The configuration will only be used when the ProcessEngine bean is present
public class YourOwnConfiguration {

    @Configuration
    @ComponentScan ("com.your.own.package.beans")
    public static class ComponentScanConfiguration {
        // This class is needed in order to conditionally perform the component scan (i.e. when the ProcessEngine bean is present)
        // It is an optional class, in case you don't need component scanning then you don't need to do this
    }

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

    @Bean
    public EngineConfigurationConfigurer<SpringProcessEngineConfiguration> customProcessEngineConfigurationConfigurer() {
        return engineConfiguration -> {
            // You can use this to add extra configuration to the process engine
        }
    }
}

Note that when using Spring Boot the configuration class can be under your own package and not under some Flowable package.
请注意,当使用Spring Boot时,配置类可以在您自己的包下,而不是在某个Flowable的包下。
In order to make this class an auto configuration class a file named spring.factories should be created in the META-INF folder of your jar. In this file you should add
为了使这个类成为一个自动配置类,应该在jar的META-INF文件夹中创建一个名为 spring.factories。在这个文件中,你应该添加

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

In order to use this approach you would need to include your jar in the WEB-INF/lib folder of the exploded war. Placing this jar in the lib folder of the servlet container (e.g. Tomcat) is not going to work due to the way Spring proxies the @Configuration classes.
为了使用这种方法,您需要将您的jar包含在解压后的war的WEB-INF/lib文件夹中。由于Spring代理@Configuration类的方式,将这个jar放在servlet容器(例如Tomcat)的lib文件夹中是行不通的。

2.组件扫描(Component scan)

Another way to provide custom Spring beans to the Flowable engine is to put them under a certain package and have the Flowable application component scan that package. Based on the application used, this package is different:
另一种向Flowable引擎提供定制Spring bean的方法是:将它们放在某个包下,然后让Flowable应用程序组件扫描该包。根据所使用的应用程序,此软件包有所不同:

  • org.flowable.rest.app for the flowable-rest.war
  • org.flowable.ui.application for the flowable-ui.war

The custom beans can be located in a single JAR and this jar should be present on the classpath when the application is starting up. Depending where there JAR is placed, the lib folder of the servlet container (e.g. Tomcat) or the WEB-INF/lib folder of the exploded war, there are different possibilities.
自定义bean可以位于单个JAR中,当应用程序启动时,这个JAR应该出现在classpath上。根据JAR的放置位置、servlet容器的lib文件夹(例如Tomcat),或被解压缩的war的WEB-INF/lib文件夹,存在不同的可能性。

When using the lib folder of the servlet container then the created classes should be self contained, i.e. they should only use classes from within the jar. You can use any of the Spring @Component annotations (with the exception of @Configuration). The reason for not being able to use @Configuration classes is the fact that each configuration class is proxied by Spring with the help of the ConfigurationClassPostProcessor. However, the classloader loading the @Configuration class does not have access to the needed classes by Spring.
When including the jar in the WEB-INF/lib folder of the exploded war then @Configuration classes and dependencies to other jars is possible.
当使用servlet容器的lib文件夹时,创建的类应该是自包含的,也就是说,它们应该只使用jar中的类。您可以使用任何Spring @Component注释(除了 @Configuration)。不能使用 @Configuration类的原因是每个配置类都由Spring在ConfigurationClassPostProcessor的帮助下代理(proxied)。但是,加载 @Configuration类的类加载器无法通过Spring访问所需的类。
当将jar包含在被解压缩的war的WEB-INF/lib文件夹中时, @Configuration类和对其他jar的依赖是可用的。

3.创建自己的Spring Boot 应用程序(Creating your own Spring Boot application)

This approach is the most flexible and most powerful approach of all. In order to follow this approach have a look at the Getting Started with Spring Boot section of this documentation.
这种方法是所有方法中最灵活和最强大的方法。为了遵循这种方法,请看一下文档中的Spring Boot入门部分(Getting Started with Spring Boot)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

月满闲庭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值