grails发布插件错误"找不到类加载插件资源[spring.resources]"

Hoo*_*oof 6 grails publish

当我使用"Realease-2.0.4"和Grails 2.0.1发布我构建的特定插件时,我得到一个奇怪的异常,我似乎无法摆脱它.我有许多具有类似设置的插件,并且这些插件都不会产生此异常.

| Error 2012-11-15 17:00:25,604 [main] ERROR plugins.DefaultGrailsPlugin  - Class not found loading plugin resource [spring.resources]. Resource skipped.
Message: spring.resources
   Line | Method
->> 202 | run       in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|   190 | findClass in java.net.URLClassLoader
|   306 | loadClass in java.lang.ClassLoader
|   247 | loadClass in     ''
|   178 | doCall .  in _PluginDependencies_groovy$_run_closure5_closure23
|   176 | doCall    in _PluginDependencies_groovy$_run_closure5
|    60 | doCall .  in _GrailsPackage_groovy$_run_closure2
|    45 | doCall    in PublishPlugin$_run_closure1
^    62 | doCall .  in     ''
| Error 2012-11-15 17:00:25,977 [main] ERROR plugins.DefaultGrailsPlugin  - Class not found loading plugin resource [spring.resources]. Resource skipped.
Message: spring.resources
   Line | Method
->> 202 | run       in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|   190 | findClass in java.net.URLClassLoader
|   306 | loadClass in java.lang.ClassLoader
|   247 | loadClass in     ''
|   178 | doCall .  in _PluginDependencies_groovy$_run_closure5_closure23
|   176 | doCall    in _PluginDependencies_groovy$_run_closure5
|    60 | doCall .  in _GrailsPackage_groovy$_run_closure2
|    45 | doCall    in PublishPlugin$_run_closure1
^    62 | doCall .  in     ''
Run Code Online (Sandbox Code Playgroud)

这就是堆栈跟踪的全部内容.

没有在grails-app/conf/spring/resources下定义的资源.

知道我怎么解决这个问题吗?

小智 0

1. 背景

\n\n

我正在使用 grails 2.4.3 和 java 1.7 开发一个自定义插件并在应用程序中使用它。自定义插件使用spring-security-core插件并添加了一些功能。该应用程序使用自定义插件并添加其他功能。这个想法是在自定义插件中设置 spring-security 和其他常见功能,并在多个项目中使用它。

\n\n

当我在conf/BuildConfig.groovy文件中使用下一个配置运行应用程序时,没有问题:

\n\n
...\ngrails.plugin.location.\'author-security-plugin\' = "../AuthorSecurityPlugin"\n...\n
Run Code Online (Sandbox Code Playgroud)\n\n

但是,当我打包插件并将其安装到我的 Maven 本地存储库时,使用以下命令:

\n\n
$ grails clean\n$ grails refresh-dependencies\n$ grails maven-install\n
Run Code Online (Sandbox Code Playgroud)\n\n

在conf/BuildConfig.groovy文件中使用下一个配置:

\n\n
dependencies {\n    // specify dependencies here under either \'build\', \'compile\', \'runtime\', \'test\' or \'provided\' scopes e.g.\n    compile: \':domino-connection-lib:\'\n    runtime: \'postgresql:postgresql:9.2-1002.jdbc4\'\n\n    //custom plugin\n    compile: "com.company:author-security-plugin:0.1"\n}\n...\n//grails.plugin.location.\'author-security-plugin\' = "../AuthorSecurityPlugin"\n...\n
Run Code Online (Sandbox Code Playgroud)\n\n

并执行 \xc2\xa8grails run-app\xc2\xa8 命令,项目抛出下一个异常:

\n\n
| Packaging Grails application.....\n2015-04-20 17:12:42,067 [main] ERROR plugins.DefaultGrailsPlugin  - Class not found loading plugin resource [spring.resources]. Resource skipped.\njava.lang.ClassNotFoundException: spring.resources\nat java.net.URLClassLoader$1.run(URLClassLoader.java:366)\nat java.net.URLClassLoader$1.run(URLClassLoader.java:355)\nat java.net.URLClassLoader.findClass(URLClassLoader.java:354)\nat java.lang.ClassLoader.loadClass(ClassLoader.java:425)\nat _PluginDependencies$_run_closure2.doCall(_PluginDependencies.groovy:48)\nat _GrailsPackage$_run_closure2.doCall(_GrailsPackage.groovy:57)\nat RunApp$_run_closure1.doCall(RunApp.groovy:28)\n
Run Code Online (Sandbox Code Playgroud)\n\n

注意: spring /resources.groovy文件包含:

\n\n
// Place your Spring DSL code here\nbeans = {\n    customAuthenticationProvider(CustomAuthenticationProvider){\n        springSecurityService=ref(\'springSecurityService\')\n        customUserService=ref(\'customUserService\')\n    }\n    ...\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

2.解决方案

\n\n

就我而言,解决方案是删除自定义插件中的 grails-app/conf/spring/resources.groovy 文件,并将其内容移至应用程序中的 grails-app/conf/spring/resources.groovy 。

\n\n

我希望这可以帮助你。

\n