Getting datasource bean that is NOT wrapped #8885
-
I have been trying to make an application that uses JDBI3. To do this I need Micronaut bean of type DataSource.
` I have been struggling with that for several days. Even a week. JDBI is so easy to work with. But getting it to work in Micronaut is NOT easy. Micronaut can deliver a DataSource bean that is "wrapped" into transaction. So Micronaut can make transaction 'seamless' cross controller and repository adapter. There are probably very good use case for the design Micronaut has taken. I sit back with a feeling that Micronaut has changed the protocol of Java's DataSource. My current solution is to implements BeanCreatedEventListener in a factory. And when I receive a DataSource of type HikariDataSource I grab the instance and serve that from my factory as "the Bean" produced in the factory. Random I do not get an event. Then I need to create my own HikariDataSource and serve that one. The reason I have to check that DataSource is a HikariDataSource it that the datasource could be a wrappedDataSource. And that datasource is useless in my use-case. I'm sitting very frustrated back and feeling that I'm using all my time on understanding Micronaut. Most of the time fighting the system. A similar problem is "transactions" this @transactional annotation that I have fightet aginst 6 months ago (and lost) - but I will save that for another debate. I have tried this` ` But I get exception:` io.micronaut.transaction.exceptions.NoTransactionException: No current transaction present. Consider declaring @transactional on the surrounding method ` That demonstrate my pointMicronaut have changed the meaning of interface DataSource .. And that makes me take many days to use Micronaut .. and always end up making very strange solutions. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Inject |
Beta Was this translation helpful? Give feedback.
Inject
DataSourceResolver
and callDataSource unwrapped = resolver.resolve(dataSource)