I am using Spring Boot 1.9 with Axon 2.3.2.
I successfully configured Spring to provide a JPA Entity Manager for the Event store, but now wish to have a second JPA entity manager/data source for persisting to the Query database. I appreciate that this is perhaps more a Spring question than an Axon one, but it occurred to me that you guys must have crossed this bridge yourselves, and wondered if you might share some examples configurations.
I use Spring 4 annotations thoughout ie no spring xml config, and after following a number of online spring examples, I am getting errors from spring, whichever way I turn.
I cannot directly post code due to client restrictions, but my working starting point is roughly as follows :
@Configuration
AxonConfigClass {
@Bean
public CommandBus commandBus() {...}
@Bean
public BeanValidationInterceptor() {...}
@Bean
public CommandGateway commandGateway {...}
@Bean
public EventStore eventStore() {...}
@Bean
public EventBus eventBus() { ...}
@Bean
public EventSourcingRepository<MyType>() myTypeRepository {...}
@Bean
public EntityManagerProvider entityManagerProvider() {
return new ContainerManagedEntityProvider();
}
}
@Configuration
PersistenceConfigClass implements EnvironmentAware {
@Override
public setEnvironment (Environment env) {
this.jpaPropertyResolver = new RelaxedPropertyResolver(env, "spring.jpa");
}
@Bean(name = "myPU")
public LocalEntityManagerFactoryBean configureEntityManagerFactory(Datasource ds, JpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
emfb.setJpaVendorAdapter(jpaVendorAdapter);
emfb.setDataSource(ds);
emfb.setPackagesToScan("org.axonframework.eventstore.jpa");
return emfb;
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager tm = new JpaTransactionManager();
tm.setEntityManagerFactory(emf);
return tm;
}
}
META-INF/persistence.xml