已在Gradle中引入spring-jdbc仍遇JdbcTransactionManager类未找到异常
问题:Spring 5.2.3.RELEASE环境下JdbcTransactionManager类找不到异常
在JDK 8环境中使用Spring版本5.2.3.RELEASE时,运行出现以下错误:
Caused by: java.lang.IllegalStateException: Failed to introspect Class ... ...
Caused by: java.lang.NoClassDefFoundError: org/springframework/jdbc/support/JdbcTransactionManager
尽管已在build.gradle中声明spring-jdbc依赖:
implementation group: 'org.springframework', name: 'spring-jdbc', version: springframeworkVersion
完整的build.gradle配置如下:
plugins { id 'java' id 'org.springframework.boot' version '2.7.5' id 'io.spring.dependency-management' version '1.0.11.RELEASE' } group = 'org.temp' version = '' repositories { maven { url 'https://ost1v.enp.aramco.com.sa:8443/repository/maven-central' credentials { username mavenuser password mavenpassword } } maven { url 'https://ost1v.enp.aramco.com.sa:8443/repository/maven-jcenter' credentials { username mavenuser password mavenpassword } } maven { url 'https://ost1v.enp.aramco.com.sa:8443/repository/maven-releases' credentials { username mavenuser password mavenpassword } } maven { url 'https://ost1v.enp.aramco.com.sa:8443/repository/maven-jaspersoft-3rd-party-ce' credentials { username mavenuser password mavenpassword } } } ext { slf4jVersion = '1.7.25' logbackVersion = '1.3.0-alpha10' jacksonDatabindVersion = '2.11.1' //2.10.1, change it to 2.12.6 springframeworkVersion = '5.3.23' //springframeworkVersion = '5.2.3.RELEASE' - This was commented to fix the problem //springSecurityVersion = '5.3.8.RELEASE' springSecurityVersion = '5.3.3.RELEASE' mybatisVersion = '3.5.6' mybatisJsr310 = '1.0.2' mybatisSpringVersion = '1.3.2' oracleJdbcVersion = '19.3.0.0' oracleSpatialVersion = '12.1.0.2' oracleXdbVersion = '12.2.1.2' lombokVersion = '1.16.20' commonsCollectionsVersion = '4.1' commonsIOVersion = '2.7' commonsLangVersion = '3.7' commonsFileuploadVersion = '1.4' commonsHttpclientVersion = '4.5.10' commonsExecVersion = '1.3' commonsBeanutilsVersion = '1.9.4' junitVersion = '4.12' mockitoVersion = '2.16.0' powermockVersion = '1.7.3' jasyptVersion = '1.9.2' hamcrestVersion = '1.3' bouncyCastleVersion = '1.64' //tokenServiceVersion = '2.0' tokenServiceVersion = '1.6-SNAPSHOT' jsonPathVersion = '2.4.0' geotoolsVersion = '18.2' itextVersion = '2.1.7.js4' jasperReportsVersion = '6.12.2' batikVersion = '1.13' fopVersion = '2.2' javaxMail = '1.5.6' freeMarker = '2.3.28' subethamail = '3.1.7' } configurations { all { exclude group: 'junit', module: 'junit' exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web:2.5.5' implementation 'org.springframework.boot:spring-boot-starter-aop:2.5.5' implementation 'org.springframework.boot:spring-boot-starter-security:2.5.5' implementation group: 'org.springframework', name: 'spring-jdbc', version: springframeworkVersion implementation group: 'org.mybatis.spring.boot',name:'mybatis-spring-boot-starter',version:'2.2.2' implementation group: 'commons-beanutils', name: 'commons-beanutils', version: commonsBeanutilsVersion implementation group: 'org.apache.commons', name: 'commons-collections4', version: commonsCollectionsVersion implementation group: 'commons-io', name: 'commons-io', version: commonsIOVersion implementation group: 'org.apache.commons', name: 'commons-lang3', version: commonsLangVersion implementation group: 'commons-fileupload', name: 'commons-fileupload', version: commonsFileuploadVersion implementation group: 'org.apache.commons', name: 'commons-exec', version: commonsExecVersion implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: commonsHttpclientVersion implementation group: 'com.oracle.ojdbc', name: 'ojdbc8', version: oracleJdbcVersion implementation group: 'org.springframework.security', name: 'spring-security-config', version: springSecurityVersion // implementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion // implementation group: 'ch.qos.logback', name: 'logback-core', version: logbackVersion // https://mvnrepository.com/artifact/org.mybatis/mybatis implementation group: 'org.mybatis', name: 'mybatis', version: '3.5.6' // https://mvnrepository.com/artifact/net.minidev/json-smart //implementation group: 'net.minidev', name: 'json-smart', version: '2.3' implementation group: 'org.mybatis', name: 'mybatis-spring', version: '2.0.0' implementation group: 'org.projectlombok', name: 'lombok', version: lombokVersion implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: bouncyCastleVersion implementation group: 'javax.mail', name: 'mail', version: '1.4.5' // 1.4.5 compileOnly fileTree(dir: 'dependencies/documentum/Shared', include: '*.jar') testImplementation group: 'junit', name: 'junit', version: junitVersion testImplementation group: 'org.springframework', name: 'spring-test', version: springframeworkVersion testImplementation group: 'org.subethamail', name: 'subethasmtp', version: subethamail testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: hamcrestVersion testImplementation group: 'org.jasypt', name: 'jasypt', version: jasyptVersion testImplementation group: 'org.jasypt', name: 'jasypt-spring31', version: jasyptVersion //testImplementation group: 'org.springframework.security', name: 'spring-security-test', version: springSecurityVersion //implementation group: 'com.github.albfernandez', name: 'itext2', version: '2.1.9' implementation group: 'net.sf.jasperreports', name: 'jasperreports', version: '6.12.2' testImplementation group: 'com.jayway.jsonpath', name: 'json-path', version: jsonPathVersion //compile group: 'com.github.albfernandez', name: 'itext2', version: '2.1.9' //compile (group: 'net.sf.jasperreports', name: 'jasperreports', version: '6.7.1') {exclude group: 'com.lowagie', module: "itext"} } test { useJUnitPlatform() }
解决方案分析
版本兼容性冲突:使用的Spring Boot版本
2.7.5默认依赖Spring Framework5.3.x系列,手动指定springframeworkVersion = '5.2.3.RELEASE'会破坏版本依赖一致性,导致spring-jdbc与其他Spring组件版本不匹配,引发类缺失问题。依赖管理插件影响:
io.spring.dependency-management插件会强制管控Spring相关依赖版本,手动指定的低版本Spring Framework可能未同步到所有关联依赖,造成部分类无法加载。验证方法:
- 执行
gradle dependencies命令,查看spring-jdbc实际依赖版本,确认是否与指定的5.2.3.RELEASE一致,若不一致说明依赖管理插件覆盖了配置。 - 检查本地仓库是否存在
spring-jdbc-5.2.3.RELEASE.jar,若不存在则说明依赖未正确下载,可能是内部仓库无该版本。
- 执行
修复步骤:
- 保持Spring Boot与Spring Framework版本兼容:Spring Boot 2.7.x对应Spring Framework 5.3.x,不要手动降级Spring Framework版本。
- 若必须使用
5.2.3.RELEASE,需将Spring Boot版本降至对应兼容的2.3.x系列,同时同步调整spring-boot-starter-web、spring-boot-starter-security等依赖版本到2.3.x。 - 清理本地仓库,执行
gradle clean build --refresh-dependencies确保依赖正确下载。
内容的提问来源于stack exchange,提问作者akarahman
相关产品推荐
相关产品推荐

