Grails 3.1集成spring-security-saml2-core启动报错求助
问题:Grails 3.1集成spring-security-saml2-core启动报错
启动服务器时出现如下错误:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfiguration' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:704) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:975) at org.springframework.beans.factory.support.DefaultListableBeanFactory.requiresEagerInitForType(DefaultListableBeanFactory.java:520) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:445) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:417) at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:191) at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:687) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:760) at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:360) at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
当前build.gradle依赖配置:
dependencies { compile "org.springframework.boot:spring-boot-starter-logging" compile "org.springframework.boot:spring-boot-starter-actuator" compile "org.springframework.boot:spring-boot-autoconfigure" compile "org.springframework.boot:spring-boot-starter-tomcat" compile 'org.springframework:springloaded:1.2.7.RELEASE' compile "org.grails:grails-dependencies" compile "org.grails:grails-web-boot" compile "org.grails.plugins:hibernate5" compile "org.hibernate:hibernate-core:5.1.0.Final" compile "org.hibernate:hibernate-ehcache:5.1.0.Final" compile "org.grails.plugins:cache" compile "org.grails.plugins:spring-security-core:3.1.1" compile "org.grails.plugins:spring-security-rest:2.0.0.M2" compile 'org.springframework.security.extensions:spring-security-saml2-core:1.0.10.RELEASE' compile 'com.lowagie:itext:2.1.7' compile ('net.sf.jasperreports:jasperreports:6.2.1') { exclude module: 'olap4j' } compile "org.grails.plugins:excel-export:2.1" compile "org.grails.plugins:mail:2.0.1" compile "com.google.maps:google-maps-services:2.1.2" compile "com.amazonaws:aws-java-sdk-s3:1.12.709" runtime "org.grails.plugins:asset-pipeline" runtime "mysql:mysql-connector-java:8.0.32" testCompile "org.grails:grails-plugin-testing" testCompile "org.grails.plugins:geb" // Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.) testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0' console "org.grails:grails-console" }
解决方案
方案一:使用Grails官方适配的spring-security-saml插件
Grails有专门适配的spring-security-saml插件,可规避原生库的版本兼容问题:
- 移除原生
spring-security-saml2-core依赖,替换为Grails插件:// 移除原依赖 // compile 'org.springframework.security.extensions:spring-security-saml2-core:1.0.10.RELEASE' // 添加适配Grails 3.1的插件版本 compile "org.grails.plugins:spring-security-saml:2.0.0" - 执行依赖清理与构建:
./gradlew clean build --refresh-dependencies
方案二:修复原生库的版本冲突
若坚持使用原生spring-security-saml2-core,需排除冲突的Spring Boot自动配置依赖:
- 修改依赖声明,排除冲突模块:
compile ('org.springframework.security.extensions:spring-security-saml2-core:1.0.10.RELEASE') { exclude group: 'org.springframework.boot', module: 'spring-boot-autoconfigure' } - 统一Spring Boot版本:Grails 3.1对应Spring Boot 1.3.x,确保所有spring-boot相关依赖使用同一版本,示例配置:
ext { springBootVersion = '1.3.8.RELEASE' } dependencies { compile "org.springframework.boot:spring-boot-starter-logging:${springBootVersion}" compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" compile "org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}" compile "org.springframework.boot:spring-boot-starter-tomcat:${springBootVersion}" // 其他依赖保持不变 } - 清理并重新构建项目:
./gradlew clean build --refresh-dependencies
额外建议
- 确保
spring-security-core版本与SAML组件兼容,当前3.1.1版本适配Grails 3.1,无需调整。 - 若上述方案无效,可尝试将
spring-security-saml2-core版本降至1.0.8.RELEASE,该版本对Spring Boot 1.3.x兼容性更佳。
内容的提问来源于stack exchange,提问作者Victor Soares
相关产品推荐
相关产品推荐

