使用 grails 安全插件时出错
Posted
技术标签:
【中文标题】使用 grails 安全插件时出错【英文标题】:Error using grails security plugin 【发布时间】:2014-10-31 06:59:54 【问题描述】:我正在使用 grails 2.4.2 并且已经安装了 grails 官方安全插件
compile ':spring-security-core:2.0-RC2'
当我第一次编译应用程序时,它给出了一个错误
| Compiling 183 source files
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] C:\Users\Shanky\Backup\myApp\target\work\plugins\spring-security-core-2.0-RC2\src\groovy\grails\plugin\springsecurity\ReflectionUtils.groovy: 205: Apparent variable 'org' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
[groovyc] You attempted to reference a variable in the binding or an instance variable from a static context.
[groovyc] You misspelled a classname or statically imported field. Please check the spelling.
[groovyc] You attempted to use a method 'org' but left out brackets in a place not allowed by the grammar.
[groovyc] @ line 205, column 18.
[groovyc] application = org.codehaus.groovy.grails.commons.ApplicationHolder.application
[groovyc] ^
[groovyc]
[groovyc] 1 error
| Compiling 183 source files.
| Error Compilation error: startup failed:
C:\Users\Shanky\Backup\myApp\target\work\plugins\spring-security-core-2.0-RC2\src\groovy\grails\plugin\springsecurity\ReflectionUtils.groovy: 205: Apparent variable 'org' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable from a static context.
You misspelled a classname or statically imported field. Please check the spelling.
You attempted to use a method 'org' but left out brackets in a place not allowed by the grammar.
@ line 205, column 18.
application = org.codehaus.groovy.grails.commons.ApplicationHolder.application
^
1 error
但是当我稍后编译该应用程序时,它编译得很好,但是当我运行该应用程序时出现错误
| Error Error generating web.xml file (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.NullPointerException
at grails.plugin.springsecurity.SpringSecurityUtils.mergeConfig(SpringSecurityUtils.java:663)
at grails.plugin.springsecurity.SpringSecurityUtils.mergeConfig(SpringSecurityUtils.java:643)
at grails.plugin.springsecurity.SpringSecurityUtils.reloadSecurityConfig(SpringSecurityUtils.java:260)
at grails.plugin.springsecurity.SpringSecurityUtils.getSecurityConfig(SpringSecurityUtils.java:227)
at SpringSecurityCoreGrailsPlugin$_closure1.doCall(SpringSecurityCoreGrailsPlugin.groovy:166)
at _GrailsPackage$_run_closure5.doCall(_GrailsPackage.groovy:74)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at _GrailsPackage$_run_closure2.doCall(_GrailsPackage.groovy:58)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
at org.codehaus.gant.GantMetaClass.processClosure(GantMetaClass.java:81)
at org.codehaus.gant.GantMetaClass.processArgument(GantMetaClass.java:95)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:128)
at RunApp$_run_closure1.doCall(RunApp.groovy:28)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners$0.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:591)
at gant.Gant.executeTargets(Gant.groovy:590)
| Error Error generating web.xml file
【问题讨论】:
嗨,Shashank Goyal。您是否在 BuildConfig 中添加了这些存储库:“repo.spring.io/milestone”“repo.grails.org/grails/core”?您对上一个 RC (RC4) 有同样的问题吗? 【参考方案1】:最新版本的 Spring Security 插件 spring-security-core 2.0-RC4
可以在 Grails 2.4.x 应用程序中使用 Holders
而不是已弃用的 ApplicationHolder
正常工作。
更新您的 BuildConfig.groovy 以使用最新版本:
BuildConfig.groovy
...
plugins
...
compile ':spring-security-core:2.0-RC4'
...
...
【讨论】:
【参考方案2】:您的 spring-security-core 版本在使用 Holders 时无法正常工作, 更新您的 BuildConfig.groovy 以使用来自Spring Security Core Plugin 的最新版本
plugins
...
compile ':spring-security-core:2.0.0'
...
【讨论】:
添加一些解释,说明此答案如何帮助 OP 解决当前问题以上是关于使用 grails 安全插件时出错的主要内容,如果未能解决你的问题,请参考以下文章
在 grails 中使用 spring-security 插件时出错
Grails 2.3 数据库迁移上的“加载插件管理器时出错:TomcatGrailsPlugin”
Grails 安装插件 rest-client-builder 1.0.2 时出错,模块描述符错误
Grails:弹簧安全插件 - 错误 springsecurity.GormPersistentTokenRepository