以前关于此错误的问题是指hibernate版本问题或运行测试.我认为这不是这种情况.
在Grails服务课程中,我有:
private static User anon = User.findByUsername('anonymous')
这就是创建错误:
Caused by IllegalStateException: Method on class [User] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.