package com.mycompany.myapp
class BootStrap {
def init = {
def adminRole = new Role(authority: 'ROLE_ADMIN').save()
def testUser = new User(username: 'me', password: 'password').save()
UserRole.create testUser, adminRole
UserRole.withSession {
it.flush()
it.clear()
}
assert User.count() == 1
assert Role.count() == 1
assert UserRole.count() == 1
}
}
运行应用程序给我这个错误:
2020-03-31 15:46:19.294错误--- [restartedMain] o.s.boot.SpringApplication :应用程序运行失败javax.persistence.TransactionRequiredException:没有事务在 进展 在org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl .java:3586)
我已经尝试使用@Transactional解决此问题,但对错误没有影响。将Bootstrap.groovy还原为默认值可以使应用程序正常运行。本教程中有哪些缺失(或不正确)导致其失败?
我正在他们的文档中遵循Grails Spring Security Core教程。当我达到24.1.5.5时,问题开始了。我被指示将Bootstrap.groovy修改为以下内容,然后运行该应用程序:...
init
是一个闭包,并且注释适用于方法或类。