javaspringmongodbspring-bootspring-mvc

Update to spring-boot-starter-parent to 3.2.12 broke spring code


Here is the exception I am getting after upgrading spring-boot-starter-parent from 3.1.12 to 3.2.12

java.lang.IllegalStateException: Failed to load ApplicationContext for [MergedContextConfiguration@6fba6a89 testClass = com.test.myapp.config.AppInitializerMongoDBTest, locations = [], classes = [com.test.myapp.core.services.ServicesConfig, com.test.myapp.core.repository.RepositoryConfig, com.test.myapp.config.PropertySources, com.test.myapp.jmx.JmxConfig, com.test.myapp.util.UtilConfig, com.test.myapp.core.async.AsyncConfig, com.test.myapp.core.identity.TenantIdentityConfig], contextInitializerClasses = [], activeProfiles = ["mongodbrepository"], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true", "spring.main.web-application-type=none"], contextCustomizers = [org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@5725a005, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@5afaf431, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@b107f13, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@16e7b37c, org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@48ee57ad, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, torg.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@25615ffd, org.spockframework.spring.mock.SpockContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@87a2127a], contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'createApplicationService' defined in com.test.myapp.core.services.ServicesConfig: Unsatisfied dependency expressed through method 'createApplicationService' parameter 0: Invalid bean definition with name 'domainModelMongoRepository' defined in com.test.myapp.core.repository.mongodb.repository.domain.DomainModelMongoRepository defined in @EnableMongoRepositories declared on MongoMetadataConfig: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'domainModelMongoRepository' defined in com.test.myapp.core.repository.mongodb.repository.domain.DomainModelMongoRepository defined in @EnableMongoRepositories declared on MongoMetadataConfig: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String

Here is dependencies of pom.xml which I think could be relavant and perhaps broken because of the upgrade but I am not able to find the correct one at the moment.

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.12</version>
    </parent>
    <dependencies>
    <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver-sync</artifactId>
            <version>4.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver-reactivestreams</artifactId>
            <version>4.11.0</version>
        </dependency>
         <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.4</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.2</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>3.4.18</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mongodb</groupId>
                    <artifactId>mongo-java-driver</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mongodb</groupId>
                    <artifactId>mongodb-driver-sync</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mongodb</groupId>
                    <artifactId>mongodb-driver-reactivestreams</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
            <version>2.7.2</version>
        </dependency>
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.12.2</version>
        </dependency>
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>2.3-groovy-3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-spring</artifactId>
            <version>2.3-groovy-3.0</version>
            <scope>test</scope>
        </dependency>
        </dependencies>

Please help with any advice or insights.


Solution

  • spring-boot-starter-parent has 653 managed dependencies, so that the project pom does not need to specify a dependency version if spring boot manages it.

    For example:

    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongodb-driver-sync</artifactId>
        <version>4.11.0</version>
    </dependency>
    

    should be using version 4.11.5. So the project pom should just be:

    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongodb-driver-sync</artifactId>
    </dependency>
    

    So the next update to spring-boot-starter-parent will automatically pick-up compatible versions. Check the other project dependencies to see if spring boot can manage them too.

    Also, some of the other dependencies not managed by spring boot are fairly old (relative to the spring-boot-starter-parent version). For example:

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

    is a major version behind. The project has somehow squeaked by until now! Each dependency should (hopefully) have some sort of compatibility matrix or upgrade guide - something like this.

    If all else fails, use the IDE to find the start up exception, to determine which dependency is causing the version compatibility mayhem.