Without registerinng events are not received, Grails 3 , boot axon 3.0.5
Can you help me?
Kind regards
ERROR
org.springframework.context.ApplicationContextException: Failed to start bean ‘eventHandlerRegistrar’; nested exception is java.lang.ClassCastException: org.springframework.beans.factory.config.MethodInvokingFactoryBean$$EnhancerBySpringCGLIB$$773ccb1d cannot be cast to org.axonframework.eventhandling.EventBus
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:114)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:879)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at es.wealth.backoffice.Application.main(Application.groovy:12)
Caused by: java.lang.ClassCastException: org.springframework.beans.factory.config.MethodInvokingFactoryBean$$EnhancerBySpringCGLIB$$773ccb1d cannot be cast to org.axonframework.eventhandling.EventBus
at org.axonframework.spring.config.AxonConfiguration$$EnhancerBySpringCGLIB$$783e9336.eventBus()
at org.axonframework.config.EventHandlingConfiguration.subscribingEventProcessor(EventHandlingConfiguration.java:83)
at org.axonframework.config.EventHandlingConfiguration.defaultEventProcessor(EventHandlingConfiguration.java:72)
at org.axonframework.config.EventHandlingConfiguration.lambda$initialize$13(EventHandlingConfiguration.java:332)
at java.util.HashMap.forEach(HashMap.java:1280)
at org.axonframework.config.EventHandlingConfiguration.initialize(EventHandlingConfiguration.java:330)
at org.axonframework.spring.config.EventHandlerRegistrar.start(EventHandlerRegistrar.java:84)
Disconnected from the target VM, address: ‘127.0.0.1:64639’, transport: ‘socket’
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175)
… 19 common frames omitted
CONFIG
package es.wealth.backoffice.config
import com.mongodb.MongoClient
import com.mongodb.MongoCredential
import com.mongodb.ServerAddress
import es.wealth.backoffice.domain.model.familygroup.FamilyGroup
import es.wealth.backoffice.domain.model.familygroup.FamilyGroupRepository
import es.wealth.backoffice.domain.model.familygroup.event.FamiliyGroupEventHandler
import es.wealth.backoffice.domain.service.FamilyGroupDomainService
import org.axonframework.config.Configurer
import org.axonframework.config.EventHandlingConfiguration
import org.axonframework.eventsourcing.AggregateFactory
import org.axonframework.eventsourcing.EventCountSnapshotTriggerDefinition
import org.axonframework.eventsourcing.EventSourcingRepository
import org.axonframework.eventsourcing.eventstore.EmbeddedEventStore
import org.axonframework.eventsourcing.eventstore.EventStore
import org.axonframework.mongo.eventsourcing.eventstore.DefaultMongoTemplate
import org.axonframework.mongo.eventsourcing.eventstore.MongoEventStorageEngine
import org.axonframework.mongo.eventsourcing.eventstore.MongoTemplate
import org.axonframework.mongo.eventsourcing.eventstore.documentperevent.DocumentPerEventStorageStrategy
import org.axonframework.serialization.json.JacksonSerializer
import org.axonframework.spring.eventsourcing.SpringAggregateSnapshotter
import org.axonframework.spring.eventsourcing.SpringAggregateSnapshotterFactoryBean
import org.axonframework.spring.eventsourcing.SpringPrototypeAggregateFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Scope
@Configuration
class AxonConfiguration {
@Autowired
FamilyGroupRepository familyGroupRepository
@Autowired
FamilyGroupDomainService familyGroupDomainService
@Bean(name = "axonMongoTemplate")
MongoTemplate axonMongoTemplate() {
// TODO config
MongoClient mongoClient = new MongoClient(new ServerAddress("mongodb", 27017), [MongoCredential.createCredential("wealth-eventstore", "wealth-eventstore", "wealth-eventstore".getChars())])
MongoTemplate template = new DefaultMongoTemplate(mongoClient,
"wealth-eventstore", "familyGroup", "familyGroup-snapshot");
template
}
@Bean
JacksonSerializer jacksonSerializer() {
new JacksonSerializer()
}
@Bean
EventStore embeddedEventStore() {
MongoEventStorageEngine storageEngine = new MongoEventStorageEngine(jacksonSerializer(), null, axonMongoTemplate(), new DocumentPerEventStorageStrategy())
EventStore eventStore = new EmbeddedEventStore(storageEngine)
eventStore
}
@Bean
SpringAggregateSnapshotterFactoryBean springAggregateSnapshotterFactoryBean() {
new SpringAggregateSnapshotterFactoryBean()
}
@Bean
@Scope("prototype")
AggregateFactory<FamilyGroup> transactionAggregateFactory() {
// TODO generic?
AggregateFactory<FamilyGroup> aggregateFactory = new SpringPrototypeAggregateFactory<FamilyGroup>()
aggregateFactory.setPrototypeBeanName("familyGroup")
aggregateFactory;
}
@Bean
@Scope("prototype")
FamilyGroup familyGroup() {
// TODO generic?
new FamilyGroup(familyGroupRepository, familyGroupDomainService)
}
@Bean
EventSourcingRepository<FamilyGroup> axonFamilyGroupRepository(EventStore eventStore, SpringAggregateSnapshotterFactoryBean springAggregateSnapshotterFactoryBean, ApplicationContext applicationContext) {
SpringAggregateSnapshotter snapshotter = springAggregateSnapshotterFactoryBean.getObject()
snapshotter.setApplicationContext(applicationContext)
EventCountSnapshotTriggerDefinition snapshotTriggerDefinition = new EventCountSnapshotTriggerDefinition(
snapshotter,
2);
new EventSourcingRepository(FamilyGroup, eventStore, snapshotTriggerDefinition)
}
@Autowired configure(Configurer configurer,EventHandlingConfiguration ehConfiguration){
// define an EventHandlingConfiguration
ehConfiguration.registerEventHandler({conf -> new FamiliyGroupEventHandler()});
// the module needs to be registered with the Axon Configuration
configurer.registerModule(ehConfiguration);
}
/*
@Bean
AggregateAnnotationCommandHandler<FamilyGroup> commandHandler(EventSourcingRepository eventSourcingRepository) {
new AggregateAnnotationCommandHandler<FamilyGroup>(FamilyGroup, eventSourcingRepository)
}
*/
}
package es.wealth.backoffice.domain.model.familygroup.event
import groovy.util.logging.Slf4j
import org.axonframework.eventhandling.EventHandler
@Slf4j
class FamiliyGroupEventHandler {
@EventHandler
void handle(FamilyGroupCreatedEvent familyGroupCreatedEvent) {
log.info "onCreate: ${familyGroupCreatedEvent}"
//familyGroupRepository.create(this)
}
}