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

时间:2017-04-06 13:43:03

标签: grails spring-security gorm grails-plugin

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

  • Grails版本:3.2.6
  • Groovy版本:2.4.7
  • JVM版本:1.8.0_91

这些是我的步骤:

  1. 我创建了插件:

    <section id="wrapper">
      <div class="bg-overlay"></div>
      <div id="content-wrap">
        <h1>
          Heading Heading Heading
        </h1>
        <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
          survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
          publishing software like Aldus PageMaker including versions of Lorem Ipsum.
        </p>
      </div>
    </section>
  2. 我添加了Spring Security核心插件,将此行添加到grails create-plugin bioprofile

    build.gradle
  3. 我运行了compile 'org.grails.plugins:spring-security-core:3.1.1' 命令来设置s2-quickstartUserRole

    UserRole
  4. 我修改了grails s2-quickstart cscie56.ps5 User Role 域类以包含一些新字段

  5. 创建了一些其他域类

    User
  6. 我生成了控制器等......

    grails create-domain-class cscie56.ps5.BlogEntry
    grails create-domain-class cscie56.ps5.Comment
    
  7. 我在grails generate-all BlogEntry grails generate-all User grails generate-all Role grails generate-all UserRole 文件中添加了以下初始化:

    BootStrap.groovy
  8. 当我使用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() { } } 运行应用时,我遇到了这个单调乏味的错误:

    grails run-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)
    

    但结果相同。

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

1 个答案:

答案 0 :(得分:1)

如果其他人有同样的问题,这对我有用。 看起来这是一个hibernate依赖问题。不明显,而且很可能是一个微妙的错误,无论是在几个文件中生成样板文件的东西(从来都不是“我会为你做所有”框架的忠实粉丝)。 在我的特定情况下(这可能是我的环境特有的)通过在build.gradle文件中用hibernate4替换生成的hibernate5依赖项,上面的错误就消失了。这就是我现在所拥有的(删除了hibernate5的东西):

classpath "org.grails.plugins:hibernate4:5.0.10"

compile "org.grails.plugins:hibernate4"
compile "org.hibernate:hibernate-core:4.3.10.Final"
compile "org.hibernate:hibernate-ehcache:4.3.10.Final"

.withTransaction {hack似乎对解决这个问题没有任何影响。