关于spring:\\”Error loading plugin manager: Tomcat Grails Plugin\\” in Grails 2.3 Database Migration

"Error loading plugin manager: TomcatGrailsPlugin" on Grails 2.3 Database Migration

我使用 Grails 2.3 和 Grails 数据库迁移插件 (1.3.6)。

当我执行 grails dbm-update 时,我收到以下错误。我该如何解决这个错误?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 Error Error loading plugin manager: TomcatGrailsPlugin (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.ClassNotFoundException: TomcatGrailsPlugin
    at _GrailsBootstrap_groovy$_run_closure2.doCall(_GrailsBootstrap_groovy:40)
    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 _GrailsBootstrap_groovy$_run_closure6.doCall(_GrailsBootstrap_groovy:64)
    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 _DatabaseMigrationCommon_groovy$_run_closure1.doCall(_DatabaseMigrationCommon_groovy:25)
    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 DbmUpdate$_run_closure1.doCall(DbmUpdate:23)
    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.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 loading plugin manager: TomcatGrailsPlugin


这是一个超级烦人的错误。我的应用程序依赖于使用 run-script 运行脚本,我得到了相同的行为。这是我作为解决方法所做的:

1
2
3
4
5
6
7
plugins {
    ...
    // grails 2.3.2 and tomcat 7.0.42 cause scripts to not work :( Pass -DnoTomcat=true in the script args to fix this
    if (System.getProperty("noTomcat") == null) {
        build":tomcat:7.0.42"
    }
}

然后在运行脚本时:

1
 grails -DnoTomcat=true run-script scripts/MyScript.groovy

确实很烦人,但至少您可以在等待修复时使用所有其他最新功能。


尝试将 buildConfig.groovy 中的 tomcat 构建类型更改为编译而不是 build:

compile ':tomcat:7.0.42'


因此,如果您发现此问题是因为您的脚本被 2.3.x 破坏了,那么这就是我发现的一般问题。我仍然不能使用 run-script,因为它总是因可怕的 TomcatPlugin 缺失问题而失败(我怀疑这意味着 run-script 总是试图引导 grails 而不管)。但是,我可以让脚本编译并作为任务运行。我的脚本总是会失败,因为我使用以下方法引导 grails:

1
2
3
4
5
6
7
includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsBootstrap")
includeTargets << grailsScript("_GrailsClasspath")

target(main:"Generate a secret key to be used with HMAC and AES algorithms") {
   depends(bootstrap)  // this is problem
}

所有这些都来自说要这样做的文档。但是,depends(bootstrap) 在 2.3.x 中被严重破坏,这是整个 fork 功能崩溃的一部分(是的,它没有经过深思熟虑)。

因为我很幸运,而且我的脚本实际上不必完全引导 grails,所以我可以执行以下操作,并且效果也很好:

1
2
3
4
5
6
7
includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsBootstrap")
includeTargets << grailsScript("_GrailsClasspath")

target(main:"Generate a secret key to be used with HMAC and AES algorithms") {
   depends(parseArguments)  // this is not problem
}

中提琴又开始工作了。工作得很好。以下是有效与无效的对比:

1
2
$ grails GenerateSecretKey              // yay works
$ grails run-script GenerateSecretKey   // doesn't work

这里有一些关于这个问题的 Jira 问题,所以你会知道什么时候所有这些都是错误的 ;-)

  • http://jira.grails.org/browse/GRAILS-11216
  • http://jira.grails.org/browse/GRAILS-11219

我使用的是 Grails 2.3.4,但这里是我解决此问题的方法:

  • 升级到数据库迁移 1.3.8
  • 清除了我的 scriptCache 文件夹
  • 执行的刷新依赖
  • 重试数据库迁移脚本,问题解决。


    只是稍微澄清一下,上面 chubbsondubs 提到过,但我在第一次阅读时错过了……

    通常对此的简单回答是:

    1
    grails run-script scripts/DoSomething

    就这样做吧:

    1
    grails do-something


    我在升级到 2.3.2 时遇到了同样的问题

    我用标志 -DnoTomcat

    尝试了上述方法

    它仍然无法正常工作。然后我意识到有一些就地插件也引用了 tomcat。这在某种程度上似乎是遗留问题,因为使用 grails 2.3.2 新创建的插件没有对 tomcat 的引用。所以我只是从插件中删除了所有引用,并将标志开关保留在我的主应用程序中。