我正在开发一个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创建一个个人实现,但我找不到一种方法来更改模式。我在网上查过了,但什么也没找到。
谢谢
问候你,穆罕默德
发布于 2020-01-25 19:36:16
您可以用不同的方式初始化PersistentTokenRepository bean中使用的dataSource变量。大多数数据源都支持模式设置。例如,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;https://stackoverflow.com/questions/58312960
复制相似问题