Micronaut-core: how to do transactionmanager

Created on 7 Jun 2018  ·  10Comments  ·  Source: micronaut-projects/micronaut-core

HI,friend
How micronaut implements transaction management and transaction annotation. Specific implementation, some demo

question

Most helpful comment

I have 3 datasources named other than default. I do get org.springframework.transaction.TransactionSystemException: No transaction manager configured. With one default and above example it works. How do you configure DataSourceTxManagerFactory with multiple datasources?

All 10 comments

give me some demo.thanks!
some problem:
ERROR io.micronaut.http.server.netty.RoutingInBoundHandler - Unexpected error occurred: No transaction manager configured
org.springframework.transaction.TransactionSystemException: No transaction manager configured
at io.micronaut.spring.tx.annotation.TransactionInterceptor.resolveTransactionManager(TransactionInterceptor.java:119)
at io.micronaut.spring.tx.annotation.TransactionInterceptor.intercept(TransactionInterceptor.java:63)

Micronaut data source injection,thanks!

@zhangsantu I've created a repo with an example that shows how to define a DataSourceTransactionManager bean. The key is create a @Factory for that bean. Take a look at this commit: https://github.com/ilopmar/micronaut-datasource-transaction-manager-example/commit/abced1ffa7031cb5dd108f6e71408124859f3846

If you comment this @Factory class https://github.com/ilopmar/micronaut-datasource-transaction-manager-example/commit/abced1ffa7031cb5dd108f6e71408124859f3846#diff-fb6f5cb1faa295212360680046092076R10 you can reproduce the issue you had about _No transaction manager..._

hi:
thanks,I will try it !thanks very match!

敬祝:工作顺利,生活开心!

张垚
北京神州云联科技有限公司
地址:北京市朝阳区北苑路甲13号院泰岳大厦21层
邮编:100107
电话:010-58847502
手机:13716252476
邮箱:[email protected]

From: Iván López
Date: 2018-06-07 21:50
To: micronaut-projects/micronaut-core
CC: zhangsantu; Mention
Subject: Re: [micronaut-projects/micronaut-core] how to do transactionmanager (#272)
@zhangsantu I've created a repo with an example that shows how to define a DataSourceTransactionManager bean. The key is create a @Factory for that bean. Take a look at this commit: ilopmar/micronaut-datasource-transaction-manager-example@abced1f
If you comment this @Factory class ilopmar/micronaut-datasource-transaction-manager-example@abced1f#diff-fb6f5cb1faa295212360680046092076R10 you can reproduce the issue you had about No transaction manager...

You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

Unfortunately this doesn't work. @Transactional doesn't commit the transaction.

I changed your example to increase a counter in the database, see this repository: https://github.com/phxql/micronaut-datasource-transaction-manager-example/tree/transactional-not-working

When curling localhost:8080/book the counter should increase every time. But it doesn't, as the transaction doesn't get commited. Note: I also disabled auto commit on the pool.

Another strange thing: when making either the class final or the method, I get this:

18:21:38.974 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Cannot inherit from final class
java.lang.VerifyError: Cannot inherit from final class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
...

Will look into it. Thanks

@phxql The reason for this is the DataSource needs to be wrapped in a TransactionAwareDataSourceProxy. For the upcoming M3 release all you will need to do is add the following dependencies:

    compile "io.micronaut:spring"
    runtime "org.springframework:spring-jdbc"

For M2 you can still make it work by taking the previous sample application and adding the following bean definition:

@Singleton
class TransactionAwareDataSourceListener implements BeanCreatedEventListener<DataSource> {
        @Override
        public DataSource onCreated(BeanCreatedEvent<DataSource> event) {
            return new TransactionAwareDataSourceProxy(event.getBean());
        }
    }

Cool, thanks! Will try that out.

Works, thank you!

I have 3 datasources named other than default. I do get org.springframework.transaction.TransactionSystemException: No transaction manager configured. With one default and above example it works. How do you configure DataSourceTxManagerFactory with multiple datasources?

Was this page helpful?
0 / 5 - 0 ratings