“遵循Grails Spring Security Core教程时发生错误,“错误。”

问题描述 投票:1回答:1
我正在遵循Grails Spring Security Core教程in their documentation。当我达到24.1.5.5时,问题开始了。我被指示将Bootstrap.groovy修改为以下内容,然后运行该应用程序:

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修改为以下内容,然后运行该应用程序:...

java spring grails spring-security
1个回答
3
投票
文档已过时。 Hibernate 5.2+现在需要事务才能进行写操作。添加@Transactional无效,因为init是一个闭包,并且注释适用于方法或类。
© www.soinside.com 2019 - 2024. All rights reserved.