从注入的数据源获取连接在 Micronaut 数据 JDBC 中抛出多个数据源的异常
Get Connection from injected DataSource throws exception with multiple datasources in Micronaut Data JDBC
无法像 spring 那样从注入的数据源获取连接,如文档中所写(配置多个数据源)https://micronaut-projects.github.io/micronaut-sql/latest/guide/#:~:text=Configuring%20Multiple%20Data%20Sources throws
Suppressed: io.micronaut.transaction.exceptions.NoTransactionException: No current transaction present. Consider declaring @Transactional on the surrounding method
at io.micronaut.transaction.jdbc.TransactionalConnectionInterceptor.intercept(TransactionalConnectionInterceptor.java:65)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
at io.micronaut.transaction.jdbc.TransactionalConnection$Intercepted.close(Unknown Source)
at com.demo.service.DemoService.processRecords(DemoService.java:116)
... 11 common frames omitted
Caused by: io.micronaut.transaction.jdbc.exceptions.CannotGetJdbcConnectionException: No current JDBC Connection found. Consider wrapping this call in transactional boundaries.
at io.micronaut.transaction.jdbc.DataSourceUtils.doGetConnection(DataSourceUtils.java:135)
at io.micronaut.transaction.jdbc.DataSourceUtils.getConnection(DataSourceUtils.java:93)
at io.micronaut.transaction.jdbc.TransactionalConnectionInterceptor.intercept(TransactionalConnectionInterceptor.java:63)
... 14 common frames omitted
我通过展开注入的 DataSource (more) 解决了我的问题:
DataSource db1Ds = ((DelegatingDataSource) db1DataSource).getTargetDataSource();
Connection db1Conn = db1Ds.getConnection();
/* or
Connection db1Conn = ((DelegatingDataSource) db1DataSource).getConnection();
*/
不知道有没有捷径
无法像 spring 那样从注入的数据源获取连接,如文档中所写(配置多个数据源)https://micronaut-projects.github.io/micronaut-sql/latest/guide/#:~:text=Configuring%20Multiple%20Data%20Sources throws
Suppressed: io.micronaut.transaction.exceptions.NoTransactionException: No current transaction present. Consider declaring @Transactional on the surrounding method
at io.micronaut.transaction.jdbc.TransactionalConnectionInterceptor.intercept(TransactionalConnectionInterceptor.java:65)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
at io.micronaut.transaction.jdbc.TransactionalConnection$Intercepted.close(Unknown Source)
at com.demo.service.DemoService.processRecords(DemoService.java:116)
... 11 common frames omitted
Caused by: io.micronaut.transaction.jdbc.exceptions.CannotGetJdbcConnectionException: No current JDBC Connection found. Consider wrapping this call in transactional boundaries.
at io.micronaut.transaction.jdbc.DataSourceUtils.doGetConnection(DataSourceUtils.java:135)
at io.micronaut.transaction.jdbc.DataSourceUtils.getConnection(DataSourceUtils.java:93)
at io.micronaut.transaction.jdbc.TransactionalConnectionInterceptor.intercept(TransactionalConnectionInterceptor.java:63)
... 14 common frames omitted
我通过展开注入的 DataSource (more) 解决了我的问题:
DataSource db1Ds = ((DelegatingDataSource) db1DataSource).getTargetDataSource();
Connection db1Conn = db1Ds.getConnection();
/* or
Connection db1Conn = ((DelegatingDataSource) db1DataSource).getConnection();
*/
不知道有没有捷径