gpt4 book ai didi

Spring Security - 未创建默认表

转载 作者:行者123 更新时间:2023-12-01 15:23:08 24 4
gpt4 key购买 nike

我正在尝试在 Spring Boot 应用程序中将 Spring Social 集成到 Spring Security 之上。但似乎 Spring Security 在创建默认表时遇到了问题,例如UserConnection、UserProfile 等,因为在成功建立与 oauth2 提供程序的连接后出现这些 SQL 错误:

PreparedStatementCallback; bad SQL grammar [select userId from UserConnection where providerId = ? and providerUserId = ?]; nested exception is org.h2.jdbc.JdbcSQLException: Tabelle "USERCONNECTION" nicht gefunden Table "USERCONNECTION" not found; SQL statement: select userId from UserConnection where providerId = ? and providerUserId = ? [42102-185]

这是spring提供的JdbcUsersConnectionRepository中的静态SQL调用。我试图切换到避免 SQL 问题的 InMemory 实现,但随后发生了下一个问题:

PreparedStatementCallback; bad SQL grammar [INSERT into userProfile(userId, email, firstName, lastName, name, username) values(?,?,?,?,?,?)]; nested exception is org.h2.jdbc.JdbcSQLException: Tabelle "USERPROFILE" nicht gefunden Table "USERPROFILE" not found; SQL statement: INSERT into userProfile(userId, email, firstName, lastName, name, username) values(?,?,?,?,?,?) [42102-185]

USERPROFILE 表也丢失了。

在我发布大量配置片段之前,您是否已经知道一些我可能已经忘记的东西告诉 spring 为我创建这些表? :)

目前我正在使用 Spring Boot 标准 H2 内存数据库,它与 JpaRepositories 配合得很好。

谢谢! :)

最佳答案

我自己找到了解决方案 :)

我最终发现第一件事情不是由一些花哨的自动 Spring 机制处理的,而是在 src/main/resources 目录中有一个普通的“schema.sql”。

create table UserConnection (
userId varchar(255) not null,
providerId varchar(255) not null,
providerUserId varchar(255),
rank int not null,
displayName varchar(255),
profileUrl varchar(512),
imageUrl varchar(512),
accessToken varchar(1024) not null,
secret varchar(255),
refreshToken varchar(255),
expireTime bigint,
primary key (userId, providerId, providerUserId));
create unique index UserConnectionRank on UserConnection(userId, providerId, rank);

create table UserProfile (
userId varchar(255) not null,
email varchar(255),
firstName varchar(255),
lastName varchar(255),
name varchar(255),
username varchar(255),
primary key (userId));
create unique index UserProfilePK on UserProfile(userId);

关于Spring Security - 未创建默认表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30218698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com