我正在开发 Spring Boot Web 应用程序,并且正在实现“记住我”功能。
我在网络安全配置中定义了以下内容:
http.authorizeRequests().and()
.rememberMe().tokenRepository(this.persistentTokenRepository())
.tokenValiditySeconds(1 * 24 * 60 * 60); // 24h
和
@Bean
public PersistentTokenRepository persistentTokenRepository() {
JdbcTokenRepositoryImpl db = new JdbcTokenRepositoryImpl();
db.setDataSource(dataSource);
return db;
}
问题是,当我在 html 页面上标记该选项时,Spring 尝试在我的数据库的默认架构中添加一个标记 ->“public”。
有什么方法可以更改该选项的默认架构吗?其他所有内容都通过此属性正确链接到正确的架构上:
spring.jpa.properties.hibernate.default_schema=another_schema_name
我尝试制作 JdbcTokenRepositoryImpl 类的个人实现,但我找不到更改架构的方法。我在网上查了一下,但什么也没找到。
谢谢
问候, 穆罕默德
最佳答案
您可以以不同的方式初始化您的 dataSource 变量,这些变量与您在 PersistentTokenRepository bean 中使用的变量不同。大多数数据源都支持模式设置。例如 Spring 的 org.springframework.jdbc.datasource.DriverManagerDataSource :
@Bean(name = "dataSource")
public DataSource getDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
// ... tipicly set username, password, driver class name, jdbc Url
dataSource.setSchema(schema);
return dataSource;
}
您可以通过提到的属性控制架构:(spring.jpa.properties.hibernate.default_schema)
@Value("${spring.jpa.properties.hibernate.default_schema}")
private String schema;
关于java - Spring - 更改 persist_logins 的架构连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58312960/