Hi,
This is a minimal reproducer for a Spring bean initialization issue I hit while migrating from Axon Framework 4 (AF4) to Axon Framework 5 (AF5).
When using a Spring bean that has a QueryGateway injected like this:
@Service
public class SettingsService {
private final QueryGateway queryGateway;
public SettingsService(QueryGateway queryGateway) {
this.queryGateway = queryGateway;
}
// some code
}
If we use this bean somewhere else, e.g., in the @Configuration class of a projection:
@Configuration
public class ProjectionConfiguration {
public static String PROCESSOR_NAME = "courses-processor";
@Bean
EventProcessorDefinition coursesProcessor(SettingsService settingsService) {
return EventProcessorDefinition
.pooledStreaming(PROCESSOR_NAME)
.assigningHandlers(descriptor -> descriptor.beanType().getPackageName()
.endsWith("coursestats.projection"))
.customized(config -> config
.initialSegmentCount(4)
.batchSize(10)
);
}
}
and there is an event handling method in that package:
@Component
class SimpleProjector {
@EventHandler
void handle(Object event, QueryUpdateEmitter emitter) {
// empty for demo purposes
}
}
we get a startup error:
Parameter 0 of constructor in org.axonframework.examples.university.projection.SettingsService required a bean of type 'org.axonframework.messaging.queryhandling.gateway.QueryGateway' that could not be found.
In our existing AF4 apps this pattern worked fine.
Suspected cause: it seems that Axon creates the EventProcessorDefinition beans very early, and at that point the QueryGateway is not yet available for constructor injection in SettingsService.
Question: do we really need to rework the Spring bean dependencies across all our apps, or is there a recommended way to handle this in AF5?
Klaus