Connecting Spring 4 app to Axon Server

Hello,
I am trying to get my Spring 4 app connected to Axon Server and it doesn’t seem to connect because it doesn’t show up in the dashboard. Any idea what I’m doing wrong? Thanks.

Here’s my config:

@Configuration

public class AxonConfiguration {

private Logger logger = LoggerFactory.getLogger(getClass());

public AxonConfiguration(Environment env) {
logger.info(“Loading Axon Configuration”);
}

@Bean
public org.axonframework.config.Configuration configuration() {
return DefaultConfigurer.defaultConfiguration()
.configureEventStore(c -> eventStore©)
.start();
}

@Bean
public AxonServerEventStore eventStore(org.axonframework.config.Configuration c) {
return AxonServerEventStore.builder()
.configuration(axonServerConfiguration())
.platformConnectionManager(axonServerConnectionManager())
.build();
}

@Bean
public AxonServerConnectionManager axonServerConnectionManager() {
return new AxonServerConnectionManager(axonServerConfiguration());
}

@Bean
public AxonServerConfiguration axonServerConfiguration() {
return AxonServerConfiguration.builder()
.componentName(“pm”)
.servers(“192.168.99.100”)
.token(“be981416-ff00-4274-a3a4-82f92735b330”)
.build();
}
}

Hi Brian.
When you are only using AxonServer as an EventStore the application will show up in the dashboard on first access of the event store (at the first append event action or when a tracking event processor is started).

Marc

I annotated the connection manager with @Bean(initMethod=“getChannel”) and it showed up.

Next thing, DefaultConfigurer.defaultConfiguration() calls ServerConnectorConfigurerModule.configureModule(Configurer) which calls configurer.registerComponent(AxonServerConfiguration.class, c -> new AxonServerConfiguration()) before configuring the buses, etc…
Outside of Spring Boot, the defaults for AxonServerConfiguration aren’t helpful, especially if you are running Axon Server in docker container (ie. unable to specify componentName, servers, token, etc,).

Prior to upgrading, I was using axon-spring which depended on Spring 4. Now, 4.0.3 depends on Spring 5.
Will it even work with Spring 4, or would I have to upgrade to use it?
For me, upgrading to Spring 5 is a bit of a daunting task because we’re using the Hibernate Criteria API which has been deprecated in Hibernate 5, so I’m not sure if the ends justify the means.

What are some of the benefits of using it outside of Spring Boot?

Lastly, I’m aware that the 2 “flavors” of config are Spring Boot, and Not Spring Boot. So, where does that leave Spring in terms of dependency injection? It seems like I have to manually “sync” Axon/Spring (ie. register axon component/expose as bean or register Spring bean as Axon component). Here’s my current latest config. @Profile is being used so I can prep the monolith for the server and enable the config at a later date.

`

@org.springframework.context.annotation.Configuration
public class AxonConfiguration {

private Logger logger = LoggerFactory.getLogger(getClass());

@Autowired
private SpecificationEventListener specificationEventListener;

public AxonConfiguration() {
logger.info(“Loading Axon Configuration”);
}

@Profile(“AxonServer”)
@Bean(destroyMethod=“shutdown”)
public Configuration serverConfiguration(AxonServerConfiguration axonServerConfiguration) {
return DefaultConfigurer.defaultConfiguration()
.registerComponent(AxonServerConfiguration.class, c -> axonServerConfiguration)
.registerComponent(AxonServerConnectionManager.class, this::buildAxonServerConnectionManager)
.eventProcessing(eventProcessingConfigurer -> eventProcessingConfigurer
.usingSubscribingEventProcessors()
.registerEventHandler(c -> specificationEventListener))
.configureEventSerializer(c -> JacksonSerializer.builder().build())
.configureEventStore(this::buildAxonServerEventStore)
.configureCommandBus(this::buildAxonServerCommandBus)
.configureQueryBus(this::buildAxonServerQueryBus)
.start();
}

@Profile("!AxonServer")
@Bean(destroyMethod=“shutdown”)
public Configuration configuration() {
return DefaultConfigurer.defaultConfiguration(false)
.eventProcessing(eventProcessingConfigurer -> eventProcessingConfigurer
.usingSubscribingEventProcessors()
.registerEventHandler(c -> specificationEventListener))
.configureEventSerializer(c -> JacksonSerializer.builder().build())
.start();
}

@Profile(“AxonServer”)
@Bean
public AxonServerConfiguration axonServerConfiguration(Properties applicationConfig) {
return AxonServerConfiguration.builder()
.componentName(applicationConfig.getProperty(“axon.axonserver.componentName”, “PM”))
.servers(applicationConfig.getProperty(“axon.axonserver.servers”, “localhost”))
.token(applicationConfig.getProperty(“axon.axonserver.token”, “”))
.build();
}

@Profile(“AxonServer”)
@Bean(initMethod=“getChannel”)
public AxonServerConnectionManager axonServerConnectionManager(Configuration c) {
return c.getComponent(AxonServerConnectionManager.class);
}

@Bean
public CommandBus commandBus(Configuration c) {
return c.getComponent(CommandBus.class);
}

@Bean
public EventBus eventBus(Configuration c) {
return c.getComponent(EventBus.class);
}

@Bean
public QueryBus queryBus(Configuration c) {
return c.getComponent(QueryBus.class);
}

private AxonServerConnectionManager buildAxonServerConnectionManager(Configuration c) {
AxonServerConnectionManager axonServerConnectionManager = new AxonServerConnectionManager(c.getComponent(AxonServerConfiguration.class));
c.onShutdown(axonServerConnectionManager::shutdown);
return axonServerConnectionManager;
}

private AxonServerEventStore buildAxonServerEventStore(Configuration c) {
return AxonServerEventStore.builder()
.configuration(c.getComponent(AxonServerConfiguration.class))
.platformConnectionManager(c.getComponent(AxonServerConnectionManager.class))
.snapshotSerializer(c.serializer())
.eventSerializer(c.eventSerializer())
.upcasterChain(c.upcasterChain())
.build();
}

private AxonServerCommandBus buildAxonServerCommandBus(Configuration c) {
AxonServerCommandBus commandBus = new AxonServerCommandBus(
c.getComponent(AxonServerConnectionManager.class),
c.getComponent(AxonServerConfiguration.class),
SimpleCommandBus.builder().build(),
c.messageSerializer(),
c.getComponent(RoutingStrategy.class, AnnotationRoutingStrategy::new),
c.getComponent(CommandPriorityCalculator.class, () -> new CommandPriorityCalculator() {}));

c.onShutdown(commandBus::disconnect);
return commandBus;
}

private QueryBus buildAxonServerQueryBus(Configuration c) {
SimpleQueryBus localSegment = SimpleQueryBus.builder()
.transactionManager(c.getComponent(TransactionManager.class, NoTransactionManager::instance))
.errorHandler(c.getComponent(QueryInvocationErrorHandler.class, () -> LoggingQueryInvocationErrorHandler.builder().build()))
.queryUpdateEmitter(c.queryUpdateEmitter())
.messageMonitor(c.messageMonitor(QueryBus.class, “localQueryBus”))
.build();

AxonServerQueryBus queryBus = new AxonServerQueryBus(
c.getComponent(AxonServerConnectionManager.class),
c.getComponent(AxonServerConfiguration.class),
c.queryUpdateEmitter(),
localSegment,
c.messageSerializer(),
c.serializer(),
c.getComponent(QueryPriorityCalculator.class, () -> new QueryPriorityCalculator() {}));

c.onShutdown(queryBus::disconnect);

return queryBus;
}
}

`

Went back and re-read the Axon 4 Documentation thread and it basically sounds like SpringAxonAutoConfigurer is deprecated and that I will need to manually “sync” Axon/Spring.