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
-------------------------------------
//SNIP
<persistence-unit name="myPU" transaction-type="RESOURCE-LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.axonframework.eventstore.jpa.DomainEntry</class>
<class>org.axonframework.eventstore.jpa.DomainEntry</class>
</provider>
application.yml
--------------------
spring:
datasource:
driverClassName: org.h2.Driver
user: sa
password: sa
url: jdbc:h2:tcp://localhost:10402/eventstore
jpa:
database-platform: org.hibernate.dialect.H2Dialect
generate-ddl: true
show-sql: false
This works, and I arrived at this config through a lot of trial and error, and Axon works fine.
My problem is with Spring, once I try and introduce multiple data sources and entity manager factories, as per the Spring online docs.
It seems that Spring is still trying to create default data source/entity managers for me, and ends up trying to set up connections to the correct db url, but without username/password.
Bottom line - does anyone have a working @ config setup they could share that shows how to setup axon with spring boot to use JPA for its event store, while also using a second JPA data source for its persistence to the Query database?
Phil
If anyone does have a pre exisiting github example of spring configured second JPA data source etc with Axon, I would still be very interested to see how you have done it, but as I have JDBI working now, don't sweat it!
Phil
--
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.