亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring - 更改 persist_logins 的架構連接

Spring - 更改 persist_logins 的架構連接

翻閱古今 2023-10-12 17:05:17
我正在開發 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;


查看完整回答
反對 回復 2023-10-12
  • 1 回答
  • 0 關注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號