问题:
研究:在https://gitlab.com/ZonZonZon/simple-axon.git上,我编写了一个简单的 Axon应用,以表明使用 Gradle-plugin插件构建的 JAR Artifact 不会(当以JAR运行时)自动配置Axon bean。虽然它在Intellij下运行良好。
从终端的项目根目录:run gradle clean build shadowJar;
java -jar build/simpleaxon.jar;
Stacktrace包含在here中。我希望Axon Autocongiguration默认提供诸如CommandBus,Snapshotter之类的bean。
问题:如何在胖子 jar 中自动配置默认轴突 bean ?
最佳答案
因此,这需要我进行一些调查才能直觉出了什么问题,但我知道问题出在哪里。
快速通知,这不是特定于Axon的事情,而是您正在使用的插件。
我运行了您的示例项目,并最终获得了相同的结果。从未有Axon bean 被接线。那使我逐步研究了创建胖JAR的过程。首先是Maven,然后是Maven的Spring Boot,然后是Spring Boot的Gradle,最后是您也引用的Shadow插件。
这项工作使我陷入了this问题,该问题最多表明“需要使用META-INF文件的项目需要将其添加到shadow插件中,并且应该对此进行记录”。
通过此引用的部分如下:
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 App无法自动配置Axon Bean,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61288081/