-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqlSessionFactoryBean falls in circular dependencies by Spring Boot's DataSourceInitializer. #58
Comments
I can also reproduce this issue with My usecase:
this also leads to the warning message mentioned above: I think the problem is in MapperFactoryBean.java (mybatis-spring) and how it is created via the "ClassPathMapperScanner". my observations:
I could fix this (using a patched mybatis-spring version) as follows: Changes to MapperFactoryBean.javaadd constructor that takes the mapperinterface as argument: public MapperFactoryBean2(Class<T> mapperInterface) {
this.mapperInterface = mapperInterface;
}
public MapperFactoryBean2() {
} Changes to ClassPathMapperScanner.javaCreate GenenericBeanDefinition (in doScan() method) using the new constructur (vs. using setMapperInterface() method): ...
// the mapper interface is the original class of the bean
// but, the actual class of the bean is MapperFactoryBean
definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName());
// NOTE: the line above replaces the line below...
//definition.getPropertyValues().add("mapperInterface", definition.getBeanClassName());
definition.setBeanClass(MapperFactoryBean2.class);
... Hope this helps and could make it into the next mybatis-spring release (as this resolved our issue). |
#58 added possibility to apply mapperInterface to MapperFactoryBean via ...
I encountered the same issue as dguggi when trying to use However, this then causes the Complete example workaround here: https://gist.github.com/rupert654/8a3af4ae04a9be71481e |
Does @dguggi's solution fix your case? |
@emacarron If you're asking to me, I don't think so. I've got the same exception but by different cause. Mine is caused by |
in mybatis-spring-1.2.3 the ClasspathMapperScanner still uses: definition.getPropertyValues().add("mapperInterface", definition.getBeanClassName()); instead of definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName()); therefore also with mybatis-1.2.3 still leads to " Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException.." |
You are right! Seems that a later PR changed that lines back. Sorry! I will remake the change again in master. |
SqlSessionFactoryBean
falls in circular dependencies by Spring Boot'sDataSourceInitializer
.With
@Lazy
annotations it's okay but without them the following exception occurs:A project with
@Lazy
annotations:https://github.com/izeye/samples-spring-boot-branches/tree/mybatis-hsqldb
A project without
@Lazy
annotations:https://github.com/izeye/samples-spring-boot-branches/tree/mybatis-hsqldb-without-lazy
I guess replacing
ApplicationListener<ApplicationEvent>
withApplicationListener<ContextRefreshedEvent>
would fix it.If my usage is incorrect, please let me know.
The text was updated successfully, but these errors were encountered: