创建后无法运行grails插件。获取错误o.s.boot.SpringApplication启动失败

创建后无法运行grails插件。获取错误o.s.boot.SpringApplication启动失败,grails,spring-security,gorm,grails-plugin,Grails,Spring Security,Gorm,Grails Plugin,我很难弄明白为什么Grails无法运行我创建的插件。这是我的环境: Grails版本:3.2.6 Groovy版本:2.4.7 JVM版本:1.8.091 以下是我的步骤: 我用以下方法创建了插件: grails create-plugin bioprofile 我通过将这一行添加到build.gradle,添加了Spring安全核心插件: compile 'org.grails.plugins:spring-security-core:3.1.1' grails s2-quickst

我很难弄明白为什么Grails无法运行我创建的插件。这是我的环境:

  • Grails版本:3.2.6
  • Groovy版本:2.4.7
  • JVM版本:1.8.091
以下是我的步骤:

  • 我用以下方法创建了插件:

    grails create-plugin bioprofile
    
  • 我通过将这一行添加到
    build.gradle
    ,添加了Spring安全核心插件:

    compile 'org.grails.plugins:spring-security-core:3.1.1'
    
    grails s2-quickstart cscie56.ps5 User Role
    
  • 我运行了
    s2快速启动
    命令来设置
    用户
    角色
    用户角色

    compile 'org.grails.plugins:spring-security-core:3.1.1'
    
    grails s2-quickstart cscie56.ps5 User Role
    
  • 我修改了
    User
    domain类以包含一些新字段

  • 创建了一些其他域类

    grails create-domain-class cscie56.ps5.BlogEntry
    grails create-domain-class cscie56.ps5.Comment
    
  • 我生成了控制器等等

    grails generate-all BlogEntry
    grails generate-all User
    grails generate-all Role
    grails generate-all UserRole
    
  • 我在
    BootStrap.groovy
    文件中添加了以下初始化:

    package bioprofile
    
    import cscie56.ps5.Role
    import cscie56.ps5.User
    import cscie56.ps5.UserRole
    
    class BootStrap {
    
        def init = { servletContext ->
            environments {
                development {
                    setupData()
                    setupUsersAndRoles()
                    println "Developement execution"
                }
                test {
                    setupData()
                    setupUsersAndRoles()
                    println "Test execution"
                }
                production {
                    // do nothing
                    println "Production execution"
                }
            }
        }
    
        def destroy = {
        }
    
        def setupUsersAndRoles() {
            User admin = new User(username: 'admin', password: 'password')
            admin.save(flush: true)
            User user = new User(username: 'user', password: 'user')
            user.save(flsuh:true)
    
            Role adminRole = new Role(authority: Role.ROLE_ADMIN)
            adminRole.save(flush:true)
    
            Role userRole = new Role(authority: Role.ROLE_USER)
            userRole.save(flush:true)
    
            UserRole.create(admin, adminRole)
            UserRole.create(admin, userRole)
            UserRole.create(user, userRole)
        }
    
        def setupData() {
    
        }
    }
    
  • 当我使用
    grailsrun-app
    运行应用程序时,我遇到了一个乏味的错误:

    Running application...
    objc[84720]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
    
    Configuring Spring Security Core ...
    ... finished configuring Spring Security Core
    
    2017-04-06 06:20:06.032 ERROR --- [           main] o.s.boot.SpringApplication               : Application startup failed
    
    java.lang.IllegalStateException: Either class [cscie56.ps5.User] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.
        at org.grails.datastore.gorm.GormEnhancer.stateException(GormEnhancer.groovy:387)
        at org.grails.datastore.gorm.GormEnhancer.findInstanceApi(GormEnhancer.groovy:273)
        at org.grails.datastore.gorm.GormEnhancer.findInstanceApi(GormEnhancer.groovy:270)
        at org.grails.datastore.gorm.GormEntity$Trait$Helper.currentGormInstanceApi(GormEntity.groovy:1326)
        at org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:151)
        at org.grails.datastore.gorm.GormEntity$Trait$Helper$save.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
        at cscie56.ps5.User.save(User.groovy)
        at cscie56.ps5.User.save(User.groovy)
        at org.grails.datastore.gorm.GormEntity$save.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at bioprofile.BootStrap.setupUsersAndRoles(BootStrap.groovy:33)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:158)
        at bioprofile.BootStrap$_closure1$_closure3$_closure4.doCall(BootStrap.groovy:13)
        at bioprofile.BootStrap$_closure1$_closure3$_closure4.doCall(BootStrap.groovy)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
        at groovy.lang.Closure.call(Closure.java:414)
        at bioprofile.BootStrap$_closure1$_closure3$_closure4.call(BootStrap.groovy)
        at groovy.lang.Closure.call(Closure.java:408)
        at bioprofile.BootStrap$_closure1$_closure3$_closure4.call(BootStrap.groovy)
        at grails.util.Environment$EnvironmentBlockEvaluator.execute(Environment.java:529)
        at grails.util.Environment.executeForEnvironment(Environment.java:510)
        at grails.util.Environment.executeForCurrentEnvironment(Environment.java:485)
        at org.grails.web.servlet.boostrap.DefaultGrailsBootstrapClass.callInit(DefaultGrailsBootstrapClass.java:62)
        at org.grails.web.servlet.context.GrailsConfigUtils.executeGrailsBootstraps(GrailsConfigUtils.java:65)
        at org.grails.plugins.web.servlet.context.BootStrapClassRunner.onStartup(BootStrapClassRunner.groovy:53)
        at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy:256)
        at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337)
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
        at grails.boot.GrailsApp$run.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
        at bioprofile.Application.main(Application.groovy:10)
    
    我试着跑

    grails clean
    grails clean --refresh-dependencies
    grails compile
    
    但同样的结果


    有人遇到过这个问题,或者知道根本原因是什么吗?

    如果其他人也会遇到同样的问题,这对我来说是有效的。 这似乎是一个hibernate依赖性问题。不明显,而且很可能是在多个文件中生成样板文件的任何东西的一个微妙缺陷(从来都不是“我会为你做一切”框架的忠实粉丝)。 在我的特定情况下(这可能特定于我的环境),通过在build.gradle文件中将生成的hibernate5依赖项替换为hibernate4,上述错误消失了。这就是我现在所做的(删除了hibernate5的内容):


    .withTransaction{hack似乎对解决此问题没有任何作用。

    问题(我仍然不了解根本原因)似乎与以下指令有关:admin.save(flush:true)adminRole.save(flush:true)userRole.save(flush:true)…因此某些东西可能没有正确初始化以允许持久性发生?.withTransaction{@vahid您能提供更多详细信息吗?这是一个重复的主题。您是否搜索过该术语。因为如果您非常确定会返回大量结果。grails中的服务在grails 3的任何其他位置都是自动事务性的,您需要围绕它包装事务。类似的主题指出缺少hibernate配置,但如下所示:就我所见,生成的配置样板在我的hibernate 5中看起来很好。这些是没有服务的域类。你能给我指出一个适当的例子吗?应该在哪里使用.withTransaction,它应该包装什么?