java.lang.IllegalStateException:类[coconut.User]不是域类或

时间:2017-06-30 02:35:54

标签: grails gorm grails-domain-class

所以我收到了这个错误。我确定它与不兼容版本的东西有关,但我不知道我做错了什么。

我是通过sdkman做的,因为我应该...... grails --version给了我3.2.11

2017-06-29 22:17:15.406 ERROR --- [nio-8080-exec-1] o.g.web.errors.GrailsExceptionResolver   : IllegalStateException occurred when processing request: [GET] /user
Either class [coconut.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.. Stacktrace follows:

java.lang.reflect.InvocationTargetException: null
        at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:211)
        at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:188)
        at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
        at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
        at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
        at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Either class [coconut.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:427)
        at org.grails.datastore.gorm.GormEnhancer.findStaticApi(GormEnhancer.groovy:296)
        at org.grails.datastore.gorm.GormEnhancer.findStaticApi(GormEnhancer.groovy:292)
        at org.grails.datastore.gorm.GormEntity$Trait$Helper.currentGormStaticApi(GormEntity.groovy:1341)
        at org.grails.datastore.gorm.GormEntity$Trait$Helper.getCount(GormEntity.groovy:627)
        at coconut.UserController.create(UserController.groovy:5)
        ... 14 common frames omitted

重现步骤

  1. 下载以下的ziped项目。
  2. grails clean; grails run-app
  3. 在第二个终端:curl localhost:8080/user
  4. 预期行为

    我没有得到那个错误。

    实际行为

    我收到了这个错误。

    环境信息

    • 操作系统:Ubuntu 17.04
    • Grails版本: 3.2.11
    • JDK版本: 1.8.0_131

    示例应用程序

    coconut-test.zip

1 个答案:

答案 0 :(得分:8)

把:

compile "org.grails.plugins:hibernate5"

进入build.gradle中的“dependencies”块