In 5.0.2, we are using the following config:
@Bean
fun springDatasourceConnectionProvider(datasource: DataSource): SpringDataSourceConnectionProvider =
SpringDataSourceConnectionProvider(datasource)
@Bean
fun tokenStore(connectionProvider: ConnectionProvider, converter: Converter): JdbcTokenStore =
JdbcTokenStore(connectionProvider, converter, JdbcTokenStoreConfiguration.DEFAULT)
We’re connecting to a postgres db using jdbc.
This config no longer works in 5.0.3, the ConnectionProvider is no longer available (I saw you did some work on that).
I changed it to:
@Bean
fun springDatasourceConnectionProvider(datasource: DataSource): SpringDataSourceConnectionProvider =
SpringDataSourceConnectionProvider(datasource)
@Bean
fun jdbcTransactionalExecutorProvider(datasource: DataSource) =
JdbcTransactionalExecutorProvider(datasource)
@Bean
fun tokenStore(jdbcTransactionalExecutorProvider: JdbcTransactionalExecutorProvider, converter: Converter): JdbcTokenStore =
JdbcTokenStore(jdbcTransactionalExecutorProvider, converter, JdbcTokenStoreConfiguration.DEFAULT)
But I’m repeatedly hitting an exception on startup:
16:40:39.298 [main] WARN o.a.m.e.p.s.p.Coordinator - Error while initializing the Token Store. This may simply indicate concurrent attempts to initialize.
java.lang.IllegalStateException: A connection executor must be present in the processing context.
at org.axonframework.messaging.core.unitofwork.transaction.jdbc.JdbcTransactionalExecutorProvider.getTransactionalExecutor(JdbcTransactionalExecutorProvider.java:73)
at org.axonframework.messaging.eventhandling.processing.streaming.token.store.jdbc.JdbcTokenStore.connectionExecutor(JdbcTokenStore.java:829)
at org.axonframework.messaging.eventhandling.processing.streaming.token.store.jdbc.JdbcTokenStore.fetchSegments(JdbcTokenStore.java:351)
at org.axonframework.messaging.eventhandling.processing.streaming.pooled.Coordinator.lambda$initializeTokenStore$0(Coordinator.java:325)
at org.axonframework.messaging.core.unitofwork.UnitOfWork.lambda$executeWithResult$0(UnitOfWork.java:163)
at org.axonframework.messaging.core.unitofwork.UnitOfWork.safe(UnitOfWork.java:178)
at org.axonframework.messaging.core.unitofwork.UnitOfWork.lambda$executeWithResult$1(UnitOfWork.java:163)
at org.axonframework.messaging.core.unitofwork.UnitOfWork$UnitOfWorkProcessingContext.lambda$safe$2(UnitOfWork.java:275)
I noticed this issue… Do I have to wait for that to be resolved, or is there an actual workaround available?
update: Source code can be found here.
Hi Maarten-Jan,
thanks for reporting this problem. This is indeed related to the issue you referenced not yet being resolved. The reason is, that some beans are missing due to the JdbcAutoConfiguration not yet included in AF 5, but there is a simple workaround for it.
When using a JdbcTokenStore you need to include the following two beans in your spring configuration for the time being (that is, until aforementioned issue is resolved):
import org.axonframework.common.jdbc.ConnectionProvider;
import org.axonframework.extension.spring.jdbc.SpringDataSourceConnectionProvider;
import org.axonframework.extension.spring.messaging.unitofwork.SpringTransactionManager;
import org.axonframework.messaging.core.unitofwork.transaction.TransactionManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
@Configuration
class AxonConfiguration {
// ... your configuration
@Bean
public ConnectionProvider connectionProvider(DataSource dataSource) {
return new SpringDataSourceConnectionProvider(dataSource);
}
@Bean
public TransactionManager axonTransactionManager(
PlatformTransactionManager transactionManager,
ConnectionProvider connectionProvider) {
return new SpringTransactionManager(transactionManager, null, connectionProvider);
}
}
The reason for this is:
- The
ConnectionProvider bean is not present because we have not yet reactivated the JdbcAutoConfiguration where it is constructed
- The
TransactionManager bean is missing because, although the JdbcTransactionAutoConfiguration is already included in 5.0.3, it is invoked before the Spring DataSourceAutoConfiguration and thus it’s condition (a DataSource bean and a PlatformTransactionManager bean present) does not trigger even if a ConnectionProvider bean would be present. Why the ordering of the autoconfigurations is that way we yet need to figure out, but i suspect it’s because the ConnectionProvider is not a hard requriement for the axonTransactionManager bean and we do not explicitly specify an autoconfiguration ordering. We’ll probably investigate that along with the reactivation of the JdbcAutoConfiguration and provide a fix as applicable.
We have scheduled the reactivation of the JdbcAutoConfiguration for 5.2.0, but can discuss if we can justify to increase the priority on this - let us know your timeline on the affected project.
I hope this resolves your issue for now, we’ll keep you posted on a permanent solution for that.
1 Like
Thanks, adding those beans resolves it!
Having this workaround in place, this issue is not really a priority anymore. I’ll keep track of this post and the upcoming release notes :-).
1 Like
We’ve moved it up in priority and will probably include the fix already in 5.1.0 because we need it in other places as well.
1 Like
Thanks to @MateuszNowak a PR for this is already underway since we require the JdbcAutoConfiguration for dead letters as well.
Well that went quick :-).