Grails - Spring 安全性不适用于 Mysql 8

Grails - Spring Security not working with Mysql 8

我有一个使用这些技术的应用程序:

问题是当我尝试将应用程序与 Mysql 8 连接时(5.6+ 它工作正常),我无法从 Grails-[=54= 获取与用户相关的信息]-安全插件。 该应用程序 运行 甚至连接到数据库,但无法验证或获取用户的信息,例如 findByUsername,其中用户名是 属性 在我的用户域 class.

我在 application.properties 文件中定义了用户域 class。

grails.plugin.springsecurity.userLookup.userDomainClassName = 'com.aaa.User'

在某些时候我发现了这个错误,但不确定它是否与此有关。

java.lang.IllegalStateException: 
Either class [com.aaa.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.

想了解为什么无法从数据库中获取信息。我已经尝试了很多事情,比如将 GORM 版本更改为 6.1.7 和 grails spring-secuirty-core 插件版本,但无法获得任何东西。

如有任何帮助,我们将不胜感激。

谢谢,

阿图尔

我们能够解决问题。当 grails-hibernate 插件寻找静态 api 与否。如果不存在,则抛出异常。

对我有用的是,我必须将 属性 放在 User 域 class:

的静态映射中
static mapping = {
table 'userTable'
id column: 'id'
password column: 'userpassword'
username column: 'username'
}

我不确定为什么会这样,当我 运行 应用程序 Mysql5.6+ 正常工作时。(驱动程序根据它)但是当 Mysql8, 它在静态映射中查找 属性.

为了解决这个问题,我还想再提一点,请确保您的 tablename、columnname 与 DB 中定义的相同。 区分大小写符合预期。

正如我提到的区分大小写,如果您将 linux 与 Mysql8 一起使用,则 lower_case_table_names=0,此检查根据 Mysql 官方文档如下:

Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement. Name comparisons are case sensitive. You should not set this variable to 0 if you are running MySQL on a system that has case-insensitive file names (such as Windows or macOS). If you force this variable to 0 with --lower-case-table-names=0 on a case-insensitive file system and access MyISAM tablenames using different lettercases, index corruption may result.

因此,如果 table 名称是静态的,是骆驼或大写,而在 db 中是小写,则它不会匹配。并且发生了错误。

希望这对某人有所帮助。