问题:
研究:在 https://gitlab.com/ZonZonZon/simple-axon.git我编了一个简单的 Axon-app 表明 JAR-artifact 建于 Gradle插件 com.github.johnrengelman.shadow
当(作为 JAR 运行时)不会自动配置 Axon bean。虽然它在 Intellij 下运行良好。
从终端中的项目根目录:
run gradle clean build shadowJar;
java -jar build/simpleaxon.jar;
堆栈跟踪被封闭 here .我希望 Axon 自动配置默认提供像 CommandBus、Snapshotter 等这样的 bean。
问题:如何在 fat jar 中自动配置默认轴突 bean ?
最佳答案
所以,这花了我一些调查来预感出了什么问题,但我知道问题是什么。
快速注意,这不是 Axon 特定的东西,而是您正在使用的插件。
我运行了您的示例项目,确实得到了相同的结果;从来没有连接过 Axon bean。这让我一步步研究了创建胖 JAR 的过程。首先是 Maven,然后是带有 Maven 的 Spring Boot,然后是带有 Spring Boot 的 Gradle,最后是你所指的 Shadow 插件。
这项努力让我找到了 this问题,其中说明“需要使用 META-INF 文件的项目需要将其添加到影子插件中,这应该记录在案”。
通过此引用的部分如下:
import com.github.jengelman.gradle.plugins.shadow.transformers.PropertiesFileTransformer
// Left out all other specifics from your 'build.gradle' file
shadowJar {
// Required for Spring
mergeServiceFiles()
append 'META-INF/spring.handlers'
append 'META-INF/spring.schemas'
append 'META-INF/spring.tooling'
transform(PropertiesFileTransformer) {
paths = ['META-INF/spring.factories' ]
mergeStrategy = "append"
}
setArchiveFileName("simpleaxon.jar")
getDestinationDirectory().set(new File(projectDir, "./build"))
}
将那条逻辑添加到您的
build.gradle
后文件,我可以按预期运行您的示例项目。
关于spring-boot - 作为 Fat JAR 运行的原始 Axon 应用程序不会自动配置 Axon Beans,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61288081/