You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Groovy应用从2.3.1升级到3.3.15启动失败求助

问题描述

将Grails应用从2.3.1版本升级到3.3.15版本后,启动时抛出以下错误:

| Running application...
2022-10-11 17:19:04.189 ERROR --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [splitseasontickets.main4.Application]; nested exception is java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes:
- org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration

完整堆栈跟踪:

at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:561)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:187)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:123)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:666)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:353)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:300)
at grails.boot.GrailsApp.run(GrailsApp.groovy:55)
at grails.boot.GrailsApp.run(GrailsApp.groovy:374)
at grails.boot.GrailsApp.run(GrailsApp.groovy:363)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
at splitseasontickets.main4.Application.main(Application.groovy:8)
Caused by: java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes:
- org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration
    at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.handleInvalidExcludes(AutoConfigurationImportSelector.java:183)
    at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.checkExcludedClasses(AutoConfigurationImportSelector.java:169)
    at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportSelector.java:97)
    at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:552)
    ... 19 common frames omitted

构建失败提示:

FAILURE: Build failed with an exception.

  • 出错原因: 任务':bootRun'执行失败。
    进程'command '/usr/lib/jvm/java-8-openjdk-amd64/bin/java''以非零退出值1结束
  • 建议尝试: 使用--stacktrace选项获取堆栈跟踪,使用--info或--debug选项获取更多日志输出。
    | 错误 启动服务器失败(使用--stacktrace查看完整跟踪信息)

项目当前Gradle依赖配置如下:

buildscript {
    repositories {
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.15.1"
    }
}

version "0.1"
group "splitseasontickets.main4"

apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"asset-pipeline"
apply plugin:"org.grails.grails-gsp"

repositories {
    mavenLocal()
    maven { url "https://repo.grails.org/grails/core" }
    mavenCentral()
}

dependencies {
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-web-boot"
    compile "org.grails:grails-logging"
    compile "org.grails:grails-plugin-rest"
    compile "org.grails:grails-plugin-databinding"
    compile "org.grails:grails-plugin-i18n"
    compile "org.grails:grails-plugin-services"
    compile "org.grails:grails-plugin-url-mappings"
    compile "org.grails:grails-plugin-interceptors"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:async"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:events"
    compile "org.grails.plugins:hibernate5"
    compile "org.hibernate:hibernate-core:5.1.16.Final"
    compile "org.grails.plugins:gsp"
    console "org.grails:grails-console"
    profile "org.grails.profiles:web"
    runtime 'org.glassfish.web:el-impl:2.2'
    runtime "com.h2database:h2"
    runtime "org.apache.tomcat:tomcat-jdbc"
    runtime 'com.bertramlabs.plugins:asset-pipeline-grails:3.4.7'
    testCompile "org.grails:grails-gorm-testing-support"
    testCompile "org.grails.plugins:geb"
    testCompile "org.grails:grails-web-testing-support"
    testCompile "org.grails.plugins:geb:1.1.2"
    testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.52.0'
    testRuntime 'net.sourceforge.htmlunit:htmlunit:2.64.0'
    testRuntime 'org.seleniumhq.selenium:selenium-chrome-driver:4.5.0'
   // compile "org.grails.plugins:hibernate"
    compile "org.hibernate:hibernate-ehcache"
    testCompile "org.grails:grails-plugin-testing"
    // Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
    compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.1-beta2'
    compile 'org.grails:grails-datastore-rest-client:6.1.9.RELEASE'
    compile 'org.codehaus.groovy:groovy-sql:3.0.13'
    //compile group: 'org.grails', name: 'grails-web-common', version: '3.0.17'
   compile group: 'org.grails', name: 'grails-core', version: '3.1.14'
    compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
    compile group: 'org.jmdware', name: 's3-bucket-recursor', version: '1.0.1'

    // compile group: 'org.apache.camel', name: 'camel-grape', version: '3.19.0'

    //compile 'org.grails.plugins:spring-security-core:3.0.3'
    compile 'org.grails.plugins:spring-security-core:3.2.0.M1'
    compile 'org.grails.plugins:spring-security-ui:3.1.2'
    compile 'org.springframework.boot:spring-boot-starter-security:1.5.4.RELEASE'
    compile group: 'org.grails', name: 'grails-plugin-controllers', version: '3.3.16'
}

bootRun {
    jvmArgs('-Dspring.output.ansi.enabled=always')
    addResources = true
    String springProfilesActive = 'spring.profiles.active'
    systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}

tasks.withType(Test) {
    systemProperty "geb.env", System.getProperty('geb.env')
    systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
    systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver')
    systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver')
}

assets {
    minifyJs = true
    minifyCss = true
}
解决方案

1. 移除对MessageSourceAutoConfiguration的错误排除

错误核心是代码中尝试排除org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration,但在Grails 3.x + Spring Boot 1.5.x环境中,这个类不是自动配置类,因此Spring Boot会抛出异常。

检查Application.groovy或其他配置类,找到类似以下的代码:

@SpringBootApplication(exclude = [MessageSourceAutoConfiguration])

或者application.yml/application.properties中的配置:

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration

将这行排除配置删除即可。

2. 统一Grails版本依赖

当前依赖中存在多个版本的Grails核心库,会导致版本冲突:

  • 删除显式指定3.1.14的grails-core依赖
  • 确保grailsVersion变量设置为3.3.15
  • 将grails-plugin-controllers版本调整为3.3.15,与目标Grails版本保持一致

3. 调整Spring Security依赖版本

spring-security-core:3.2.0.M1是里程碑版本,建议替换为与Grails 3.3.15兼容的稳定版本,比如3.2.3:

compile 'org.grails.plugins:spring-security-core:3.2.3'
compile 'org.grails.plugins:spring-security-ui:3.1.2' // 确保UI版本与核心兼容

同时删除显式的spring-boot-starter-security依赖,由Grails依赖管理自动引入匹配版本的Spring Security。

4. 清理冗余与过时依赖

  • 删除重复的geb依赖,保留testCompile "org.grails.plugins:geb:1.1.2"即可
  • 将httpcore:4.1-beta2升级到稳定版,比如4.4.16
  • 检查grails-datastore-rest-client:6.1.9.RELEASE,若存在兼容性问题可升级到6.1.18.RELEASE(与Grails 3.3.x兼容)

5. 验证依赖一致性

运行以下命令查看依赖树,排查并解决所有版本冲突:

./gradlew dependencies --configuration compile

内容的提问来源于stack exchange,提问作者Rahul kumar dhiman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 12:01:19