NoClassDefFoundError org.codehaus.groovy.grails.plugins.springsecurity.ui.RegistrationCode仅适用于run-app

时间:2012-05-22 14:53:40

标签: grails

我在grails应用程序中有一个奇怪的情况。我的应用程序使用spring-security-ui,我正在使用类 org.codehaus.groovy.grails.plugins.springsecurity.ui.RegistrationCode
奇怪的是,当我使用这个类时,应用程序抛出异常:

java.lang.NoClassDefFoundError: org.codehaus.groovy.grails.plugins.springsecurity.ui.RegistrationCode

但是如果我尝试打开 grails shell 并编写一个导入该类的脚本,它就可以了。 如果我生成 war 并将其部署在Tomcat上,则应用程序可以正常运行。 只是 run-app 才行不通。 这可能是导致此错误的原因?
感谢

更新:
现在,当我尝试注册用户或登录时,我的情况相同......

2012-07-10 12:24:40,835  ERROR org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver - NoClassDefFoundError occurred when processing request: [GET] /myapplication/dashboard
org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils.
Stacktrace follows:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LoginController': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [LoginController]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:909)
   at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [LoginController]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
   ... 3 more
Caused by: java.lang.NoClassDefFoundError: org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
   ... 3 more

但是如果我将这段代码放在控制器中就可以了:

println org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils.class

有人建议吗?

更多信息:

Plug-ins you currently have installed are listed below:
-------------------------------------------------------------
blueprint           1.0.2            --  Blueprint CSS framework
burning-image       0.6.0            --  Burning Image
ckeditor            3.6.2.1          --  CKeditor plugin
constraints         0.6.0            --  Custom domain constraints plugin
famfamfam           1.0.1            --  Silk icons from famfamfam.com
hibernate           2.0.1            --  Hibernate for Grails
invoicer            0.1              --  Invoicer Plugin
jdbc-pool           0.3              --  Tomcat JDBC Pool plugin
jquery              1.7.1            --  JQuery for Grails
jquery-ui           1.8.15           --  jQuery UI resources
jquery-validation   1.7.3            --  JQuery Validation Plugin
jquery-validation-ui1.2.3            --  JQuery Validation UI Plugin - Client Side Validation without writing JavaScript
lesscss-resources   1.3.0.3          --  Less CSS Resources
mail                1.0              --  Provides Mail support to a running Grails application
quartz              0.4.2            --  This plugin adds Quartz job scheduling features to Grails application.
rendering           0.4.3            --  Grails Rendering
resources           1.1.6            --  Resources
spring-security-core1.2.7.2          --  Spring Security Core Plugin
spring-security-ui  0.2              --  Spring Security UI
tomcat              2.0.1            --  Apache Tomcat plugin for Grails
webxml              1.4.1            --  WebXmlConfig

我有一些类来管理从另一家公司开发的插件中的spring安全用户,角色和控制器。 但这很奇怪,因为 NoClassDefFoundError 是针对SpringSecurityUtils类的,如果我尝试在控制器中导入它,它可以正常工作......

1 个答案:

答案 0 :(得分:0)

问题是您的开发环境中不包含该库: 只需在BuildConfig.groovy文件中添加依赖项,即可将库添加到开发环境中:

dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

        runtime 'mysql:mysql-connector-java:5.1.20'
        runtime 'apacheexec:commons-exec:1.1' // this is the external library that I added which is the apache commons exec.
    }

了解更多信息请访问此页面: http://grails.org/doc/latest/guide/conf.html#configurationsAndDependencies

我希望它有所帮助