SqlSessionFactoryBean falls in circular dependencies by Spring Boot's DataSourceInitializer.
See original GitHub issueSqlSessionFactoryBean
falls in circular dependencies by Spring Boot’s DataSourceInitializer
.
With @Lazy
annotations it’s okay but without them the following exception occurs:
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
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>
with ApplicationListener<ContextRefreshedEvent>
would fix it.
If my usage is incorrect, please let me know.
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Circular Dependencies in Spring - Baeldung
A quick writeup on dealing with circular dependencies in Spring: how they occur and several ways to work around them.
Read more >springboot - SqlSessionFactoryBean falls in circular dependencies ...
springboot mybatis配置多数据源的时候,报错:There is a circular dependency between 7 beans in the application con.
Read more >June 2015 - The MyBatis Blog
SqlSessionFactoryBean falls in circular dependencies by Spring Boot's DataSourceInitializer, see http://github.com/mybatis/spring/issues/58.
Read more >Cyclic dependency when there are multiple DataSource defined
I created the two "first" and "second" DataSources inside the method which creates the routing datasource so that they don't have to be...
Read more >Bountysource
SqlSessionFactoryBean falls in circular dependencies by Spring Boot's DataSourceInitializer.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can also reproduce this issue with mybatis-spring-1.2.2, mybatis-3.2.8, spring-boot-1.2.2, spring-4.1.5
My usecase:
this also leads to the warning message mentioned above: “Requested bean is currently in creation: Is there an unresolvable circular reference?”
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.java
add constructor that takes the mapperinterface as argument:
Changes to ClassPathMapperScanner.java
Create GenenericBeanDefinition (in doScan() method) using the new constructur (vs. using setMapperInterface() method):
Hope this helps and could make it into the next mybatis-spring release (as this resolved our issue).
You are right! Seems that a later PR changed that lines back. Sorry!
I will remake the change again in master.