Search code examples
springspring-bootstack-overflow

Spring boot 2.0.6 -


I am upgrading my app to Spring boot 2.0.6. Maven builds and runs, the unit tests fine. At runtime, while starting up the application container though

I keep seeing this error:-

2018-11-21 11:55:30,190 WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodValidationPostProcessor' defined in class path resource

[org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.validation.beanvalidation.MethodValidationPostProcessor]: Factory method 'methodValidationPostProcessor' threw exception; nested exception is java.lang.StackOverflowError.

The dependencies in my parent pom are as follows -

`<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
    </parent>
 <properties>
    <capitalone.project.version>3.0.1</capitalone.project.version>
    <jackson.version>2.9.7</jackson.version>
    <junit.version>4.12</junit.version>
    <junit-platform.version>1.1.0</junit-platform.version>
    <sl4j.version>1.7.25</sl4j.version>
    <spring-data-releasetrain.version>Lovelace-RELEASE</spring-data-releasetrain.version>
    <mongodb.version>3.8.2</mongodb.version>
    <pmd.version>3.11.0</pmd.version>
    <jacoco.version>0.8.2</jacoco.version>
    <docker.useConfigFile>false</docker.useConfigFile>
    <mockito.version>2.23.0</mockito.version>
    <docker-maven-plugin.version>1.2.0</docker-maven-plugin.version>
    <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
    <sonar-maven-plugin.version>3.5.0.1254</sonar-maven-plugin.version>
    <maven-source-plugin.version>3.0.1</maven-source-plugin.version>
    <maven-javadoc-plugin.version>3.0.1</maven-javadoc-plugin.version>
    <maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
    <commons-beanutils.version>1.9.3</commons-beanutils.version>
    <hibernate-validator.version>6.0.13.Final</hibernate-validator.version>
</properties>
<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${sl4j.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-properties-migrator</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
            <version>2.0.6.RELEASE</version>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-releasetrain</artifactId>
                <version>${spring-data-releasetrain.version}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.RELEASE</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>

        </dependencies>
    </dependencyManagement>`
The pom of my project inherits the above dependencies as it is its parent. Additionally it has the following dependencies defined in it -
<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <hamcrest.version>1.3</hamcrest.version>
        <querydsl.version>4.2.1</querydsl.version>
    </properties>
<dependencies>
        <dependency>
            <groupId>com.capitalone.dashboard</groupId>
            <artifactId>core</artifactId>
            <version>${capitalone.project.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>${querydsl.version}</version>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-mongodb</artifactId>
            <version>${querydsl.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mongodb</groupId>
                    <artifactId>mongo-java-driver</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-jpa</artifactId>
            <version>${querydsl.version}</version>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-core</artifactId>
            <version>${querydsl.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.fakemongo</groupId>
            <artifactId>fongo</artifactId>
            <version>2.0.3</version>
        </dependency>
    </dependencies>

I have run out of options now. It looks like its going into some kind of cyclical dependency but not sure what will resolve it. Any help is greatly appreciated.


Solution

  • Just so it might help someone else, I found this post with almost the same stacktrace - https://github.com/ulisesbocchio/jasypt-spring-boot/issues/50

    For me, the problem persisted with Spring boot 2.1.0.RELEASE as well as all the other versions specified in that github forum post.

    Eventually, when I ran the application as a normal Spring Boot App via intellij (Yes, Run as Application), it started throwing a different error in the console suggesting that the property names in my properties files were in camel case and they had to be all in lowercase and could have dash(-). After I changed all the property names, it could instantiate the bean alright and the application started up.