spring-boot - 作为 Fat JAR 运行的原始 Axon 应用程序不会自动配置 Axon Beans

标签 spring-boot gradle axon fatjar

问题:

研究:在 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/

相关文章:

android - 在根项目 'bintrayUpload' 中找不到任务 'bin'

java - 无法从更新的 org.json 包中导入类

cqrs - @AggregateIdentifier & @TargetAggregateIdentifier 的理解

spring - NoHandlerForCommandException 与 axon-spring-boot-starter

java - 向并发用户分配数据

java - SLF4J : Class path contains multiple SLF4J bindings. 无法摆脱绑定(bind)

gradle - Gradle中的OSGi bundle 构建问题

java - 是否可以启动嵌入在我的 spring-boot 应用程序中的 Axon 服务器?

java - 在 Spring Boot 中为 @WebMvcTest 禁用 Spring Security 配置类

java - 如何使用Spring Security自定义登录页面?