Analysis and Solution of IllegalStateException Caused by Spring Boot Dependency Version Conflicts

Nov 22, 2025 · Programming · 10 views · 7.8

Keywords: Spring Boot | Dependency Conflict | IllegalStateException | Gradle | Auto-configuration

Abstract: This article provides an in-depth analysis of the common java.lang.IllegalStateException error in Spring Boot applications, particularly those caused by dependency version conflicts. Through practical case studies, it demonstrates how to identify and resolve NullPointerException issues during Spring Boot auto-configuration processes, offering detailed dependency management and version control strategies. The article combines the use of Gradle build tools to provide specific configuration examples and best practice recommendations, helping developers avoid similar problems.

Problem Background and Error Analysis

During Spring Boot application development, various auto-configuration related exceptions are frequently encountered. Among them, java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration is a typical error caused by dependency management issues.

Root Cause Analysis

Based on the problem description and error stack trace, it can be determined that the core issue lies in the inconsistency of Spring Boot dependency versions. Specifically manifested as:

@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource primaryDataSource() {
  return DataSourceBuilder.create().build();
}

In the build.gradle configuration, although Spring Boot version 1.1.8.RELEASE is explicitly specified, other modules referenced in the project may contain different versions of Spring Boot dependencies:

dependencies {
    compile project(':common')
    compile project(':adapter')
    compile project(':persistence')
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '1.1.8.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.1.8.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.1.8.RELEASE'
}

Dependency Conflict Mechanism

Spring Boot's auto-configuration mechanism relies on conditional annotations (such as @ConditionalOnClass, @ConditionalOnProperty, etc.) to determine whether to enable specific auto-configuration classes. When multiple different versions of Spring Boot components exist in the classpath, the condition evaluation process may exhibit unpredictable behavior.

The NullPointerException occurring in the OnPropertyCondition.getMatchOutcome method indicates that certain necessary environment properties or configuration information failed to initialize correctly during the condition evaluation process. This is typically caused by conflicts in class loading and initialization processes between different versions of Spring Boot components.

Solutions and Best Practices

Unified Dependency Version Management

In Gradle build files, the Spring Boot plugin should be used to uniformly manage all Spring Boot related dependency versions:

plugins {
    id 'org.springframework.boot' version '2.7.0'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}

springBoot {
    mainClass = "storm.Application"
}

dependencies {
    implementation project(':common')
    implementation project(':adapter')
    implementation project(':persistence')
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
}

Dependency Tree Analysis

Use Gradle's dependency tree analysis functionality to identify potential version conflicts:

./gradlew dependencies

Or analyze specific configurations:

./gradlew dependencies --configuration compileClasspath

Related Case Analysis

The similar issues mentioned in the reference article further confirm the importance of dependency version management. In the Spring Security WebSocket configuration case, the absence of necessary dependency classes MessageSecurityMetadataSource led to similar IllegalStateException and NoClassDefFoundError.

This type of class loading failure issue shares similar roots with the dependency version conflicts discussed in this article – inconsistency in component versions within the classpath.

Preventive Measures

Using BOM (Bill of Materials)

Spring Boot provides the dependency-management plugin, which can automatically manage versions of all Spring Boot related dependencies:

dependencyManagement {
    imports {
        mavenBom "org.springframework.boot:spring-boot-dependencies:2.7.0"
    }
}

Version Consistency in Modular Projects

In multi-module projects, ensure all submodules use the same version of Spring Boot dependencies:

// In root project's build.gradle
ext {
    set('springBootVersion', '2.7.0')
}

// Uniform usage in all submodules
implementation "org.springframework.boot:spring-boot-starter:${springBootVersion}"

Conclusion

The stable operation of Spring Boot applications depends on the consistency of all component versions. Through unified dependency management strategies, regular dependency tree analysis, and reasonable modular design, IllegalStateException and other auto-configuration related issues caused by version conflicts can be effectively avoided. In actual development, it is recommended to always use the dependency management methods recommended by Spring Boot official documentation and regularly update to stable versions.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.