Spring-boot: Using together with mybatis-spring-boot occurred the StackOverflowError when deploying war file

Created on 19 Oct 2017  路  5Comments  路  Source: spring-projects/spring-boot

Since 2.0.0.M5, the StackOverflowError occur at deploying the war file to the application server(such as Tomcat).

Log

...
2017-10-18 15:23:21.649  INFO 14288 --- [ost-startStop-1] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-10-18 15:23:21.659 ERROR 14288 --- [ost-startStop-1] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybatis-org.mybatis.spring.boot.autoconfigure.MybatisProperties': Initialization of bean failed; nested exception is java.lang.StackOverflowError
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1269) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1126) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) ~[spring-boot-2.0.0.M5.jar:2.0.0.M5]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.0.0.M5.jar:2.0.0.M5]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) ~[spring-boot-2.0.0.M5.jar:2.0.0.M5]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.0.M5.jar:2.0.0.M5]
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:155) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
...

Reproduce application

Remarks

  • It works fine until 2.0.0.M4
  • It works fine using IDE execution feature
  • It works fine using ./mvnw clean spring-boot:run
  • It works fine using java -jar foo.war

Related Issues

  • mybatis/spring-boot-starter#193
regression

Most helpful comment

I've submitted PR for the reproduce application on spring-projects/spring-boot-issues#72.

All 5 comments

I've submitted PR for the reproduce application on spring-projects/spring-boot-issues#72.

Thanks for the sample @kazuki43zoo! This is related to JNDI and the binding apparently, see more complete stacktrace

The fix that went in for #9801 causes this to break. ResultMapping from iBatis has a List<ResultMapping> and leads to a StackOverflowException. I've added a test case to reproduce that. Also added a test case for being able to bind to a nested collection. I'm not yet sure about how we can achieve the behavior required for #9801 and prevent this failure.

A temporary workaround is adding the -Dspring.jndi.ignore=true on VM option. However, there is the limitation that cannot use the JNDI property source feature.

@mbhave pointed out I missed a @Test annotation, when added things fail.

Was this page helpful?
0 / 5 - 0 ratings