Axon 参考指南
  • 介绍
  • 架构概览
    • DDD & CQRS 概念
    • 事件溯源
    • 事件驱动的微服务
  • Axon Server
  • 发行说明
    • Axon Framework
      • Major Releases
      • Minor Releases
    • Axon Server
      • Major Releases
      • Minor Releases Standard Edition
      • Minor Releases Enterprise Edition
    • Axon Framework Extensions
      • AMQP
        • Major Releases
      • CDI
        • Major Releases
      • JGroups
        • Major Releases
      • Kafka
        • Major Releases
        • Minor Releases
      • Kotlin
        • Experimental Releases
      • Mongo
        • Major Releases
        • Minor Releases
      • Reactor
        • Major Releases
        • Minor Releases
      • Spring Cloud
        • Major Releases
        • Minor Releases
      • Tracing
        • Major Releases
        • Minor Releases
  • Getting Started
    • 快速开始
  • Axon Framework
    • 介绍
    • 消息传递概念
      • 消息剖析
      • 消息关联
      • 消息拦截
      • 支持带注解的处理程序
      • 异常处理
      • 工作单元
    • 命令
      • 建模
        • 聚合
        • 多实体聚合
        • 聚合状态存储
        • 从另一个聚合创建聚合
        • 聚合多态性
        • 解决冲突
      • 命令调度器
      • 命令处理程序
      • 基础设施
      • 配置
    • 事件
      • 事件调度器
      • 事件处理程序
      • 事件处理器
        • 订阅事件处理器
        • 流式事件处理器
      • 事件总线和事件存储
      • 事件版本控制
    • 查询
      • 查询处理
      • 查询调度器
      • 查询处理程序
      • 实现
      • 配置
    • 长时处理过程(Sagas)
      • 实现
      • 关联
      • 基础设施
    • Deadlines
      • Deadline Managers
      • Event Schedulers
    • 测试
      • 命令 / 事件
      • 长时处理过程(Sagas)
    • 序列化
    • 调整
      • 事件快照
      • 事件处理
      • 命令处理
    • 监控和指标
    • Spring Boot 集成
    • 模块
  • Axon Server
    • 介绍
    • 安装
      • 本地安装
        • Axon Server SE
        • Axon Server EE
      • Docker / K8s
        • Axon Server SE
        • Axon Server EE
    • 管理
      • 配置
        • System Properties
        • Command Line Interface
        • REST API
        • GRPC API
      • Monitoring
        • Actuator Endpoints
        • gRPC Metrics
        • Heartbeat Monitoring
      • Clusters
      • Replication Groups
      • Multi-Context
      • Tagging
      • Backup and Messaging-only Nodes
      • Backups
      • Recovery
      • Plugins
      • Error Codes
    • 安全
      • SSL
      • 访问控制
      • 访问控制 - 标准版
      • 访问控制 - 企业版
      • 访问控制 - 客户端应用程序
      • 访问控制 - 命令行
      • 访问控制 - REST API
      • 访问控制 - LDAP
      • 访问控制 - OAuth 2.0
    • 性能
      • 事件段
      • 流量控制
    • 迁移
      • Standard to Enterprise Edition
      • Non-Axon Server to Axon Server
  • Extensions
    • Spring AMQP
    • JGroups
    • Kafka
    • Kotlin
    • Mongo
    • Reactor
      • Reactor Gateways
    • Spring Cloud
    • Tracing
  • Appendices
    • A. RDBMS Tuning
    • B. Message Handler Tuning
      • 参数解析器
      • 处理程序增强
    • C. 元数据注解
    • D. 标识符生成
    • E. Axon Server Query Language
由 GitBook 提供支持
在本页
  • Auto-configuration
  • JPA & Persistence Contexts
  • Demystifying Axon Spring Boot Starter
  1. Axon Framework

Spring Boot 集成

Spring Boot Integration

Axon Framework provides extensive support for Spring, but does not require you to use Spring in order to use Axon. All components can be configured programmatically and do not require Spring on the classpath. However, if you do use Spring, much of the configuration is made easier with the use of Spring's annotation support. Axon provides Spring Boot starters on the top of that, so you can benefit from auto-configuration as well.

Auto-configuration

Axon's Spring Boot auto-configuration is by far the easiest option to get started configuring your Axon components. By simply declaring dependency to axon-spring-boot-starter, Axon will automatically configure the infrastructure components (command bus, event bus, query bus), as well as any component required to run and store aggregates and sagas.

JPA & Persistence Contexts

With Spring Data-JPA, a JPA Persistence Context is automatically configured. Axon's Spring Boot Autoconfiguration module will make sure Axon's JPA Entities are automatically registered with this default context.

However, when you explicitly include certain packages, for example using an @EntityScan annotation, this autoconfiguration will not happen anymore. If you then wish to use JPA based components from Axon, you will need to make sure the right Entities are registered.

To register Axon's JPA Entities, include the relevant packages, as described below:

  • org.axonframework.eventhandling.tokenstore contains the entities necessary for the TokenStore used by Event Processors.

  • org.axonframework.modelling.saga.repository.jpa contains the entities necessary to persist Sagas

  • org.axonframework.eventsourcing.eventstore.jpa contains the entities necessary for the JPA Event Storage engine, when using a relational database as the Event Store.

Demystifying Axon Spring Boot Starter

With a lot of things happening in the background, it sometimes becomes difficult to understand how an annotation or just including a dependency enables so many features.

axon-spring-boot-starter follows general Spring boot convention in structuring the starter. It depends on axon-spring-boot-autoconfigure which holds concrete implementation of Axon auto-configuration. When Axon Spring Boot application starts up, it looks for a file named spring.factories in the classpath. This file is located in the META-INF directory of axon-spring-boot-autoconfigure module:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
    org.axonframework.springboot.autoconfig.MetricsAutoConfiguration,\
    org.axonframework.springboot.autoconfig.EventProcessingAutoConfiguration,\
    org.axonframework.springboot.autoconfig.AxonAutoConfiguration,\
    org.axonframework.springboot.autoconfig.JpaAutoConfiguration,\
    org.axonframework.springboot.autoconfig.JpaEventStoreAutoConfiguration,\
    org.axonframework.springboot.autoconfig.JdbcAutoConfiguration,\
    org.axonframework.springboot.autoconfig.TransactionAutoConfiguration,\
    org.axonframework.springboot.autoconfig.NoOpTransactionAutoConfiguration,\
    org.axonframework.springboot.autoconfig.InfraConfiguration,\
    org.axonframework.springboot.autoconfig.ObjectMapperAutoConfiguration,\
    org.axonframework.springboot.autoconfig.AxonServerAutoConfiguration

This file maps different configuration classes which Axon Spring boot application will try to apply. So, as per this snippet, Spring Boot will try to apply all the configuration classes for AxonServerAutoConfiguration, AxonAutoConfiguration, ...

Whether these configuration classes will be applied or not, it will depend on conditions defined on this classes:

  • AxonServerAutoConfiguration configures Axon Server as implementation for the Command Bus, Query Bus and Event Store. It will be applied before AxonAutoConfiguration, and it will be applied only if the org.axonframework.axonserver.connector.AxonServerConfiguration class is available in the classpath. Axon Server auto configuration can be disabled by setting the axon.axonserver.enabled property to false in the .properties/.yml file.

  • AxonAutoConfiguration configures a 'non-axon-server' implementation of Command Bus, Query Bus, Event Store/Event Bus and other Axon components. These components will be initialized only if they are not in the Spring Application context already, eg. @ConditionalOnMissingBean(EventBus.class). As AxonAutoConfiguration will be applied after AxonServerAutoConfiguration these Axon components will be in the Spring Application Context already, and therefore Axon Server's implementation of Command Bus, Query Bus and Event Store/Event Bus will win.

Axon Spring Boot auto-configuration is not intrusive. It will define only Spring components that you haven't already explicitly defined in the application context. This allow you to completely override the auto-configured beans by defining your own in one of the @Configuration classes.

Specific Axon (Spring) component configurations will be explained in detail in the following sections of this guide.

上一页监控和指标下一页模块

最后更新于2年前