Hi Vlad,
I would like them to be able to control Spring SQL transactions.
I am not sure what that means, but it is possible to let MyBatis use Spring managed beans.
You need to create a custom ObjectFactory
that looks up ApplicationContext
.
The create
method would look as follows.
public <T> T create(Class<T> type) {
try {
return applicationContext.getBean(type);
} catch (NoSuchBeanDefinitionException e) {
return delegate.create(type);
}
}
delegate
is an instance of DefaultObjectFactory
.
Set this ObjectFactory
to your SqlSessionFactoryBean
.
@Bean
public SqlSessionFactoryBean sqlSessionFactory() {
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setObjectFactory(new SpringBeanObjectFactory(applicationContext));
...
Here is an executable demo:
https://github.com/harawata/mybatis-issues/tree/master/ml-20190524T021118
Regards,
Iwao
--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CAP3Y0VaHJDctWxFo5wJRtKO0QDsAAaRdEpNHuupreu5bf-QhqA%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mybati...@googlegroups.com.