簡體   English   中英

將 Spring 事件偵聽器添加到 Camunda BPM Run Docker

[英]Adding a Spring event listener to the Camunda BPM Run Docker

我想做一些由 Camunda 流程實例 state 更改觸發的工作,因此為 Camunda 編寫了 Spring 注釋驅動的事件偵聽器。

我已經將它打包到 JAR 文件中:代碼和pom.xml在 Gist here上。

我編寫了一個 Dockerfile 擴展camunda/camunda-bpm-platform:run-7.14.0並將生成的 JAR 插入/camunda/configuration/userlib

這肯定在 Spring 引導加載程序路徑中,根據ps

10 camunda   0:31 java -Dloader.path=/camunda/internal/webapps/,/camunda/internal/rest/,/camunda/configuration/userlib/,/camunda/configuration/keystore/ -Dcamunda.deploymentDir=/camunda/configuration/resources -jar /camunda/internal/camunda-bpm-run-core.jar --spring.config.location=file:/camunda/configuration/default.yml

檢查日志,Camunda 肯定會啟動 Spring 事件:

o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-001: Initialized Camunda Spring Boot Eventing Engine Plugin.
o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-003: Task events will be published as Spring Events.
o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-005: Execution events will be published as Spring Events.
o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-007: History events will be published as Spring events.

但我沒有看到我的任何日志消息。

這讓我懷疑僅僅在加載器上放置一個 JAR 不足以讓 Spring 引導找到監聽器 - 但我不知道我還缺少什么。

任何幫助將非常感激。 謝謝!

好的,我意識到我在這里做錯了。 我錯誤地假設類路徑上的任何 JAR 文件都會自動初始化它們的類,這反過來意味着 Spring 會注意到@Component@EventListener注釋,然后......做一些魔術來添加監聽器。 這不是真的。

我現在明白正確的做法是使用 Camunda Initializr 構建一個全新的Spring 引導應用程序,其中包括我的偵聽器,然后圍繞它滾動 Docker。 所以這就是我現在前進的道路。

您只需要確保您聲明的任何 Spring 組件都屬於配置的Spring 組件掃描@see eg https://www.baeldung.com/spring-component-scanning

在您的情況下,這可能僅意味着您需要將 package 名稱調整為應用程序 class 的 package 的子包。 或者,您可以添加配置以將 Spring 組件掃描擴展到您的包。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM