Eventhandler outside aggregate is raising classcastexception on runtime,

582 views
Skip to first unread message

Fernando París

unread,
Jul 12, 2017, 10:22:23 AM7/12/17
to Axon Framework Users
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(<generated>)
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)
}

}


Fernando París

unread,
Jul 14, 2017, 3:28:39 AM7/14/17
to Axon Framework Users
TO enhace some info its important to mention that our aim is to receive events outside the aggregate: we werent able at all with tons of differents configuration

Can you help us to be able to handle events on  an non aggregate pojo with axon + springboot?

regards

Allard Buijze

unread,
Jul 15, 2017, 8:28:09 AM7/15/17
to Axon Framework Users
There's a lot of configuration that doesn't make a lot of sense to me. It doesn't need to be wrong, but when having problems like what you're describing, less is more. Classcast exceptions like these typically occur in messy Spring configuration, where a beandefinition overrides another one, which happens to deliver a different type of bean.

Instead of defining a bean of type EventStore, just define the EventStorageEngine. The Axon Spring Boot Starter module will autoconfigure the rest.
If you want to use Event Sourcing, don't specify any repositories. Just annotate your aggregate root class with @Aggregate. Also, don't define the aggregate itself, nor the aggregateFactory as beans. That's all done automatically.

Try to avoid registering event handlers using the eventHandlingConfiguration. If they're Spring @Component annotated and have @EventHandler methods, they are autodiscovered.

Once everything works as expected, you can provide additional configuration for snapshotting.

Cheers,

Allard

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Fernando París

unread,
Jul 17, 2017, 11:24:07 AM7/17/17
to axonfr...@googlegroups.com
If i do this the following error raises. I cannot hide reactor dependevy. It is used


Added to this if we finally make it work, how can we configure snapshotting? Ive tested to get the eventstore but no bean defined..





g.springframework.context.ApplicationContextException: Failed to start bean 'org.axonframework.spring.config.AxonConfiguration'; nested exception is java.lang.ClassCastException: reactor.bus.EventBus cannot be cast to org.axonframework.eventhandling.EventBus
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:167)
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: reactor.bus.EventBus cannot be cast to org.axonframework.eventhandling.EventBus
at org.axonframework.spring.config.SpringAxonAutoConfigurer.lambda$null$5(SpringAxonAutoConfigurer.java:122)
at org.axonframework.config.Component.get(Component.java:73)
at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.getComponent(DefaultConfigurer.java:344)
at org.axonframework.config.Configuration.getComponent(Configuration.java:114)
at org.axonframework.config.Configuration.eventBus(Configuration.java:50)
at org.axonframework.config.AggregateConfigurer.lambda$new$9(AggregateConfigurer.java:98)
at org.axonframework.config.Component.get(Component.java:73)
at org.axonframework.config.AggregateConfigurer.lambda$new$11(AggregateConfigurer.java:110)
at org.axonframework.config.Component.get(Component.java:73)
at org.axonframework.config.AggregateConfigurer.start(AggregateConfigurer.java:175)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at org.axonframework.config.DefaultConfigurer.invokeStartHandlers(DefaultConfigurer.java:292)
at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.start(DefaultConfigurer.java:355)
at org.axonframework.spring.config.AxonConfiguration.start(AxonConfiguration.java:127)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175)
... 20 common frames omitted


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 org.axonframework.eventsourcing.EventCountSnapshotTriggerDefinition
import org.axonframework.eventsourcing.EventSourcingRepository
import org.axonframework.eventsourcing.eventstore.EmbeddedEventStore
import org.axonframework.eventsourcing.eventstore.EventStorageEngine

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.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class AxonConfiguration {


@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
    EventStorageEngine embeddedEventStore() {

MongoEventStorageEngine storageEngine = new MongoEventStorageEngine(jacksonSerializer(), null, axonMongoTemplate(), new DocumentPerEventStorageStrategy())
        //EventStore eventStore = new EmbeddedEventStore(storageEngine)
storageEngine
}


/*@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)
    }*/

/*
@Bean
AggregateAnnotationCommandHandler<FamilyGroup> commandHandler(EventSourcingRepository eventSourcingRepository) {
new AggregateAnnotationCommandHandler<FamilyGroup>(FamilyGroup, eventSourcingRepository)
}
*/

}




Enviado con Mailtrack

To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.

Fernando París

unread,
Jul 21, 2017, 7:19:53 AM7/21/17
to Axon Framework Users
Any help will be very welcome :)

Allard Buijze

unread,
Jul 21, 2017, 8:34:01 AM7/21/17
to Axon Framework Users
It seems that you're injecting a bean of type reactor.bus.EventBus in a place where an Axon Event Bus (org.axonframework.eventhandling.EventBus) is expected.

The exception occurs when Axon tries to get the EventBus it has previously defined from the application context. However, in your context, another bean has overridden the EventBus with a bean of type reactor.bus.EventBus.
By default, Axon calls it's EventBus (or EventStore) bean "eventBus". Either change the bean name for the reactor.bus.EventBus to avoid this conflict, or explicitly define another bean name for the Axon EventBus/Store.

Cheers,

Allard

To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframewor...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.

Fernando París

unread,
Aug 1, 2017, 3:48:58 PM8/1/17
to Axon Framework Users
Eventbus problem, but after cleaning up configuration, same problem raises when defining @component con eventhandler

Any ideas?
package es.wealth.backoffice.config

import com.mongodb.MongoClient
import com.mongodb.MongoCredential
import com.mongodb.ServerAddress
import es.wealth.backoffice.domain.model.client.event.ClientEventHandler
import es.wealth.backoffice.domain.model.contract.Contract
import es.wealth.backoffice.domain.model.familygroup.FamilyGroup
import es.wealth.backoffice.domain.model.kyc.Kyc
import es.wealth.backoffice.domain.model.person.NaturalPerson
import org.axonframework.config.EventHandlingConfiguration
import org.axonframework.eventhandling.EventBus
import org.axonframework.eventhandling.EventHandler
import org.axonframework.eventhandling.SimpleEventHandlerInvoker

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.stereotype.Aggregate
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.Primary

@Configuration
class AxonConfiguration {

@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", "events", "events-snapshot");

template
}

@Bean
JacksonSerializer jacksonSerializer() {
new JacksonSerializer()
}

    @Primary
@Bean(name = "eventBusser")

EventStore embeddedEventStore() {
MongoEventStorageEngine storageEngine = new MongoEventStorageEngine(jacksonSerializer(), null, axonMongoTemplate(), new DocumentPerEventStorageStrategy())
EventStore eventStore = new EmbeddedEventStore(storageEngine)
eventStore
}

    /*@Bean
    SpringAggregateSnapshotterFactoryBean springAggregateSnapshotterFactoryBean() {
new SpringAggregateSnapshotterFactoryBean()
}

@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)
}

    @Bean
EventSourcingRepository<NaturalPerson> axonNaturalPersonRepository(EventStore eventStore, SpringAggregateSnapshotterFactoryBean springAggregateSnapshotterFactoryBean, ApplicationContext applicationContext) {
        SpringAggregateSnapshotter snapshotter = springAggregateSnapshotterFactoryBean.getObject()
snapshotter.setApplicationContext(applicationContext)
EventCountSnapshotTriggerDefinition snapshotTriggerDefinition = new EventCountSnapshotTriggerDefinition(
snapshotter,
2)

        new EventSourcingRepository(NaturalPerson, eventStore, snapshotTriggerDefinition)
}

@Bean
EventSourcingRepository<Contract> axonContractRepository(EventStore eventStore, SpringAggregateSnapshotterFactoryBean springAggregateSnapshotterFactoryBean, ApplicationContext applicationContext) {
        SpringAggregateSnapshotter snapshotter = springAggregateSnapshotterFactoryBean.getObject()
snapshotter.setApplicationContext(applicationContext)
EventCountSnapshotTriggerDefinition snapshotTriggerDefinition = new EventCountSnapshotTriggerDefinition(
snapshotter,
2)

        new EventSourcingRepository(Contract, eventStore, snapshotTriggerDefinition)
}

@Bean
EventSourcingRepository<Kyc> axonKycRepository(EventStore eventStore, SpringAggregateSnapshotterFactoryBean springAggregateSnapshotterFactoryBean, ApplicationContext applicationContext) {
        SpringAggregateSnapshotter snapshotter = springAggregateSnapshotterFactoryBean.getObject()
snapshotter.setApplicationContext(applicationContext)
EventCountSnapshotTriggerDefinition snapshotTriggerDefinition = new EventCountSnapshotTriggerDefinition(
snapshotter,
2)

        new EventSourcingRepository(Kyc, eventStore, snapshotTriggerDefinition)
    }*/

/*
@Bean
AggregateAnnotationCommandHandler<FamilyGroup> commandHandler(EventSourcingRepository eventSourcingRepository) {
new AggregateAnnotationCommandHandler<FamilyGroup>(FamilyGroup, eventSourcingRepository)
}
*/



}


package es.wealth.backoffice.domain.model.client.event

import groovy.util.logging.Slf4j
import org.axonframework.eventhandling.EventHandler
import org.springframework.stereotype.Component

@Component
@Slf4j
class ClientEventHandler {

@EventHandler
void onEvent(ClientCreatedEvent clientCreatedEvent){
log.info("IT WORKSS!!!!!!YEAHH")
}
}

Allard Buijze

unread,
Aug 1, 2017, 4:13:32 PM8/1/17
to Axon Framework Users
It seems that the bean called "eventBus" isn't the Axon Event Bus at the end of the Spring Context initialization. Most likely because the bean is being overwritten with a bean of another type.

Are you sure the below is the only configuration in effect?

Op di 1 aug. 2017 om 21:49 schreef Fernando París <ferp...@gmail.com>:

Fernando París

unread,
Aug 1, 2017, 4:36:57 PM8/1/17
to axonfr...@googlegroups.com
Yes sure. Search eventBus on all the project but no luck



Enviado con Mailtrack

To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.

Allard Buijze

unread,
Aug 2, 2017, 12:34:06 AM8/2/17
to axonfr...@googlegroups.com
Hi,

one thing that you could try to work around the problem, is to not define a bean for the EventStore, but only for the MongoEventStorageEngine. In that case, Axon will configure an EventStore/Bus for you.

Cheers,

Allard

Fernando París

unread,
Aug 2, 2017, 4:02:01 AM8/2/17
to axonfr...@googlegroups.com
Only with eventstoragengine  

org.springframework.context.ApplicationContextException: Failed to start bean 'org.axonframework.spring.config.AxonConfiguration'; nested exception is java.lang.ClassCastException: reactor.bus.EventBus cannot be cast to org.axonframework.eventhandling.EventBus
Enviado con Mailtrack

To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.

Fernando París

unread,
Aug 2, 2017, 4:02:15 AM8/2/17
to axonfr...@googlegroups.com
Any other clue?



Enviado con Mailtrack

Allard Buijze

unread,
Aug 2, 2017, 4:06:43 AM8/2/17
to axonfr...@googlegroups.com
To me, this is an indication that something is wrong in the Spring configuration. Apparently, Spring found and (Axon) EventBus and when Axon tries to get the event bus out of the Spring context to use it, it is suddenly become a reactor Event Bus. This means that bean definitions are being overwritten with beans of a different type.

Where does the reactor.bus.EventBus come from? What name did you give that bean? Perhaps there is a naming conflict between Axon and Reactor.

Allard

Op wo 2 aug. 2017 om 10:02 schreef Fernando París <ferp...@gmail.com>:

Fernando París

unread,
Aug 2, 2017, 5:52:44 AM8/2/17
to axonfr...@googlegroups.com
Its used on grails oauth plugin. Its defined on the library





Enviado con Mailtrack

To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.

Steven van Beelen

unread,
Aug 2, 2017, 7:44:44 AM8/2/17
to axonfr...@googlegroups.com
This there any change you can override the bean name of that specific library? For example by specifying your own reactor.bus.EventBus for the oauth plugin, but with an added @Qualifier to adjust the name, to alleviate the conflict between Axon's EventBus?

Otherwise, you'll have to do that on the Axon side.
So create an Axon EventBus, with an added @Qualifier to the bean definition to give it a non-conflicting name with the plugin's EventBus.
You'll have to do the correct wiring of Axon's EventBus yourself then though.

Cheers,

Steven

Fernando París

unread,
Aug 2, 2017, 10:23:24 AM8/2/17
to axonfr...@googlegroups.com
If i debug , on the messagesource.apply(conf) call, ConfigurationClassEnhancer is called on method, with beanName eventBud.

Is there anyway to search for eventbus con apply conf, with other name?




private SubscribingEventProcessor subscribingEventProcessor(Configuration conf, String name, List<?> eh,
Function<Configuration, SubscribableMessageSource<? extends EventMessage<?>>> messageSource) {
return new SubscribingEventProcessor(name,
new SimpleEventHandlerInvoker(eh,
conf.parameterResolverFactory(),
conf.getComponent(
ListenerInvocationErrorHandler.class,
LoggingErrorHandler::new)),
messageSource.apply(conf),
DirectEventProcessingStrategy.INSTANCE,
PropagatingErrorHandler.INSTANCE,
conf.messageMonitor(SubscribingEventProcessor.class,
name));
}

private static class BeanMethodInterceptor implements MethodInterceptor, ConditionalCallback {

/**
* Enhance a {@link Bean @Bean} method to check the supplied BeanFactory for the
* existence of this bean object.
* @throws Throwable as a catch-all for any exception that may be thrown when invoking the
* super implementation of the proxied method i.e., the actual {@code @Bean} method
*/
@Override
public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object[] beanMethodArgs,
MethodProxy cglibMethodProxy) throws Throwable {

ConfigurableBeanFactory beanFactory = getBeanFactory(enhancedConfigInstance);
String beanName = BeanAnnotationHelper.determineBeanNameFor(beanMethod);

// Determine whether this bean is a scoped-proxy
Scope scope = AnnotatedElementUtils.findMergedAnnotation(beanMethod, Scope.class);
if (scope != null && scope.proxyMode() != ScopedProxyMode.NO) {
String scopedBeanName = ScopedProxyCreator.getTargetBeanName(beanName);
if (beanFactory.isCurrentlyInCreation(scopedBeanName)) {
beanName = scopedBeanName;
}
}

Enviado con Mailtrack

To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframework+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/03pKZLhYIp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.

Steven van Beelen

unread,
Aug 4, 2017, 6:04:03 AM8/4/17
to axonfr...@googlegroups.com
Sorry Fernando, but I'm not sure what you were going at with trying that debugging.

What I meant was, either create a reactor.bus.EventBus bean with another name tied to it (by using the @Qualifier({the-name-you-want-it-to-have})), or create an axon EventBus with another name. So adjust your configuration file to create either one of the EventBusses with a different name.

By doing that, there will not be a name clash in Spring, and thus the Axon EventBus will not get overwritten by the 
reactor.bus.EventBus.
And that should also mean you'll not get the ClassCastException you've posted initially.

Hope this helps.

Cheers,

Steven

Fernando París

unread,
Aug 4, 2017, 12:07:39 PM8/4/17
to axonfr...@googlegroups.com
I did that already with no luck
Same error

Allard Buijze

unread,
Aug 5, 2017, 4:19:10 AM8/5/17
to axonfr...@googlegroups.com
Hi Fernando,

I've managed to reproduce an issue that is slightly different than this problem, but may be a sign of what's going on here.

In the complex dance between Axon and Spring, there is a piece of configuration in Axon that makes Spring believe it should use the bean name "eventBus" to locate the Event Bus, even if another name has been explicitly assigned to it.

So if you name your Axon EventBus (or Store) to 'eventBus' and rename the other one, you should be able to work around the issue.

Cheers,

Allard

Fernando París

unread,
Aug 23, 2017, 1:05:05 PM8/23/17
to Axon Framework Users
Finally we got it working with other bean name, and finally we needed to override default processor. tons of time of dbugging but reached the goal !!!

@Bean
EventStore embeddedEventStore() {
MongoEventStorageEngine storageEngine = new MongoEventStorageEngine(jacksonSerializer(), null, axonMongoTemplate(), new
DocumentPerEventStorageStrategy())
EventStore eventStore = new EmbeddedEventStore(storageEngine)
eventStore
}

@Bean(name = 'eventBas')
@Primary
EventBus eventBas(EventStore eventStore) {

eventStore
}

@Bean
SpringAggregateSnapshotterFactoryBean springAggregateSnapshotterFactoryBean() {
new SpringAggregateSnapshotterFactoryBean()
}

@Bean
EventSourcingRepository<FamilyGroup> axonFamilyGroupRepository(EventStore eventStore, SpringAggregateSnapshotterFactoryBean
springAggregateSnapshotterFactoryBean, ApplicationContext applicationContext) {
    SpringAggregateSnapshotter snapshotter = springAggregateSnapshotterFactoryBean.object
    snapshotter.setApplicationContext(applicationContext)
EventCountSnapshotTriggerDefinition snapshotTriggerDefinition = new EventCountSnapshotTriggerDefinition(
snapshotter,
            SNAPSHOT_TRESHOLD)


new EventSourcingRepository(FamilyGroup, eventStore, snapshotTriggerDefinition)
}

@Bean
EventSourcingRepository<NaturalPerson> axonNaturalPersonRepository(EventStore eventStore, SpringAggregateSnapshotterFactoryBean
springAggregateSnapshotterFactoryBean, ApplicationContext applicationContext) {
    SpringAggregateSnapshotter snapshotter = springAggregateSnapshotterFactoryBean.object
    snapshotter.setApplicationContext(applicationContext)
EventCountSnapshotTriggerDefinition snapshotTriggerDefinition = new EventCountSnapshotTriggerDefinition(
snapshotter,
            SNAPSHOT_TRESHOLD)

new EventSourcingRepository(NaturalPerson, eventStore, snapshotTriggerDefinition)
}

@Bean
EventSourcingRepository<Contract> axonContractRepository(EventStore eventStore, SpringAggregateSnapshotterFactoryBean
springAggregateSnapshotterFactoryBean, ApplicationContext applicationContext) {
    SpringAggregateSnapshotter snapshotter = springAggregateSnapshotterFactoryBean.object
    snapshotter.setApplicationContext(applicationContext)
EventCountSnapshotTriggerDefinition snapshotTriggerDefinition = new EventCountSnapshotTriggerDefinition(
snapshotter,
            SNAPSHOT_TRESHOLD)


new EventSourcingRepository(Contract, eventStore, snapshotTriggerDefinition)
}

@Bean
EventSourcingRepository<Kyc> axonKycRepository(EventStore eventStore, SpringAggregateSnapshotterFactoryBean
springAggregateSnapshotterFactoryBean, ApplicationContext applicationContext) {
    SpringAggregateSnapshotter snapshotter = springAggregateSnapshotterFactoryBean.object
    snapshotter.setApplicationContext(applicationContext)
EventCountSnapshotTriggerDefinition snapshotTriggerDefinition = new EventCountSnapshotTriggerDefinition(
snapshotter,
            SNAPSHOT_TRESHOLD)

new EventSourcingRepository(Kyc, eventStore, snapshotTriggerDefinition)
}

@Autowired
void configure(EventBus eventBus, EventHandlingConfiguration ehConfig) {
ehConfig.registerSubscribingEventProcessor(PROCESSOR_CLASSPATH) { c -> eventBus }
//ehConfig.registerEventHandler({c -> new ClientEventHandler()})
ehConfig.byDefaultAssignTo(PROCESSOR_CLASSPATH)
}
...
Reply all
Reply to author
Forward
0 new messages