I got past that issue, as I had a bean initialized for an EventBus (which I read is essentially an event store).
Now I’m having a problem with: org.axonframework.commandhandling.NoHandlerForCommandException: No handler was subscribed to command
For more context…Here is my application class – note that I have some things commented out as I’ve been trying different things:
@SpringBootApplication
@ComponentScan(basePackages = {“com.ge.energy.bids.demand.eventsourcing”})
@EntityScan(basePackages = {“com.ge.energy.bids.demand.eventsourcing”,
“org.axonframework.eventsourcing.eventstore.jpa”,
“org.axonframework.eventhandling.saga.repository.jpa”,
“org.axonframework.eventhandling.tokenstore.jpa”})
@EnableJpaRepositories(basePackages = {“com.ge.energy.bids.demand.eventsourcing”})
public class DemandBiddingServiceApplication {
private static final Logger logger = LoggerFactory.getLogger(DemandBiddingServiceApplication.class);
static SimpleCommandBus commandBus = new SimpleCommandBus();
CommandGateway commandGateway = new DefaultCommandGateway(commandBus);
public static void main(String[] args) {
SpringApplication.run(DemandBiddingServiceApplication.class, args);
logger.info(“Spring boot application started!”);
}
// @Bean
// Repository bidRepository(EntityManagerProvider entityManagerProvider, EventBus eventBus)
// {
// Repository todoRepository = new GenericJpaRepository(
// entityManagerProvider,
// BidRepository.class,
// eventBus
// );
// return todoRepository;
// }
@Bean
@Primary
public Serializer serializer() {
return new JacksonSerializer();
}
// @Bean
// public EventStorageEngine eventStorageEngine() throws Exception {
// return new JpaEventStorageEngine(entityManagerProvider(), springTransactionManager());
// }
//
// @Bean
// public EntityManagerProvider entityManagerProvider() {
// return new ContainerManagedEntityManagerProvider();
// }
//
// @Bean
// public SpringTransactionManager springTransactionManager() throws Exception {
// return new SpringTransactionManager(transactionManager());
// }
//
// @Bean
// public PlatformTransactionManager transactionManager() throws PropertyVetoException {
// return new JpaTransactionManager(entityManagerFactory);
// }
//
// @Bean
// public TransactionManagerFactoryBean transactionManagerFactoryBean() throws PropertyVetoException {
// TransactionManagerFactoryBean factoryBean = new TransactionManagerFactoryBean();
// factoryBean.setTransactionManager(transactionManager());
//
// return factoryBean;
// }
Here is my aggregate class:
@Aggregate
public class BidAggregate {
@AggregateIdentifier
private String mrid;
private String name;
private long fixedMw;
public BidAggregate()
{
System.out.println("--------------------------------------------------");
System.out.println(“Loaded Aggregate”);
System.out.println("--------------------------------------------------");
}
@CommandHandler
public BidAggregate(CreateBidCommand command)
{
apply(new BidCreatedEvent(command.getMrid(), command.getName(), command.getFixedMw()));
}
@EventHandler
public void on(BidCreatedEvent event)
{
this.mrid = event.getMrid();
this.name = event.getName();
this.fixedMw = event.getFixedMw();
}
@CommandHandler
public BidAggregate(AlterBidCommand command)
{
apply(new BidAlteredEvent(command.getMrid(), command.getName(), command.getFixedMw()));
}
@EventHandler
public void on(BidAlteredEvent event)
{
this.mrid = event.getMrid();
this.name = event.getName();
this.fixedMw = event.getFixedMw();
}
Here are my command classes:
@Value
public class AlterBidCommand {
@TargetAggregateIdentifier
private final String mrid;
private final String name;
private final long fixedMw;
public AlterBidCommand(String mrid, String name, long fixedMw) {
this.mrid = mrid;
this.name = name;
this.fixedMw = fixedMw;
}
public String getMrid() {
return mrid;
}
public String getName() {
return name;
}
public long getFixedMw()
{
return fixedMw;
}
@Value
public class CreateBidCommand {
@TargetAggregateIdentifier
private final String mrid;
private final String name;
private final long fixedMw;
public CreateBidCommand(String mrid, String name, long fixedMw) {
this.mrid = mrid;
this.name = name;
this.fixedMw = fixedMw;
}
public String getMrid() {
return mrid;
}
public String getName() {
return name;
}
public long getFixedMw()
{
return fixedMw;
}
Event classes:
@Value
public class BidAlteredEvent {
private String mrid;
private String name;
private long fixedMw;
public BidAlteredEvent(String mrid, String name, long fixedMw) {
this.mrid = mrid;
this.name = name;
this.fixedMw = fixedMw;
}
public String getMrid() {
return mrid;
}
public String getName() {
return name;
}
public long getFixedMw() {
return fixedMw;
}
@Value
public class BidCreatedEvent {
private String mrid;
private String name;
private long fixedMw;
public BidCreatedEvent(String mrid, String name, long fixedMw) {
this.mrid = mrid;
this.name = name;
this.fixedMw = fixedMw;
}
public String getMrid() {
return mrid;
}
public String getName() {
return name;
}
public long getFixedMw() {
return fixedMw;
}
I am trying to get a events to appear through my JPA connection. I can connect to my database and I do see the tables generated properly once the application kicks off. It just always complains about the handlers.
Finally my event handler class:
@Component
public class BidsEventHandler {
@EventHandler
public void handle(BidCreatedEvent event) {
System.out.println(“Bid Created: " + event.getMrid() + " (” + event.getMrid() + “)”);
}
@EventHandler
public void handle(BidAlteredEvent event) {
System.out.println(“Bid Altered: " + event.getMrid() + " (” + event.getMrid() + “)”);
}
Any help would be greatly appreciated, I can tell I am close – but I’m clearly missing something inherent here.