我正在開發 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 類的個人實現,但我找不到更改架構的方法。我在網上查了一下,但什么也沒找到。謝謝
1 回答

繁星coding
TA貢獻1797條經驗 獲得超4個贊
您可以以不同的方式初始化您的 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;
添加回答
舉報
0/150
提交
取消