1. Phenomenon
When writing spring program normally, an error is reported suddenly:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'blogDao' defined in org.maoge.nameddemo.BeanConfig:
Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.maoge.nameddemo.BlogDao]: Factory method 'blogDao' threw exception;
nested exception is java.lang.StackOverflowError
2. Analysis and treatment
Several keywords: beancreationexception, beaninstantiation via factory method failed, beaninstantiationexception, stackoverflow error.
It can be analyzed that there is an error in the generated bean, and then we can see that there is a stackoverflow error indicating that there is a memory overflow, which should be caused by an infinite loop.
Look at the code:
@Bean
public BlogDao blogDao() {
BlogDao blogDao=new BlogDao();
blogDao.setNamedParameterJdbcTemplate(namedParameterJdbcTemplate());//注入namedParameterJdbcTemplate
return blogDao();
}
I’ll go. Blogdao () calls blogdao (), and I call myself.
To be amended as follows:
@Bean
public BlogDao blogDao() {
BlogDao blogDao=new BlogDao();
blogDao.setNamedParameterJdbcTemplate(namedParameterJdbcTemplate());//注入namedParameterJdbcTemplate
return blogDao;
}
It’s done!
Similar Posts:
- Cannot resolve reference to bean ‘entityManagerFactory’ while setting constructor argument
- mybatis: Property ‘configuration’ and ‘configLocation’ can not specified with together
- [Solved] Springboot startup error: org.springframework.beans.factory.unsatisfieddependenceexception…
- How to Solve the login error of Spring + Shiro CacheManager
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans’ defined in class path resource
- MappedBy reference an unknown target entity property [How to Solve]
- [Solved] Import AOP Error: error at ::0 formal unbound in pointcut
- [Solved] Caused by: java.lang.ClassNotFoundException: org.mybatis.logging.LoggerFactory
- [Solved] JAVA Error: org.springframework.beans.factory.BeanCreationException
- [Solved] java.lang.ClassNotFoundException: org.apache.log4j.Logger