Spring Security 启用Remember-me 功能 jdbcTokenRepository.setCreateTableOnStartup(true)

其实记住我默认实现是在内存中的,点开这个类可以看到 org.springframework.security.web.authentication.rememberme.InMemoryTokenRepositoryImpl

1436393-c84df256cd2d4acd.png
image.png
1436393-593045c14add13f4.png
image.png
1436393-eb85de46bb10f73d.png
image.png
    @Bean
    public PersistentTokenRepository persistentTokenRepository() {
        JdbcTokenRepositoryImpl jdbcTokenRepository = new JdbcTokenRepositoryImpl();
        jdbcTokenRepository.setCreateTableOnStartup(true);
       //这一行报错,原因缺少JDBC依赖
       jdbcTokenRepository.setDataSource(dataSource);
        return jdbcTokenRepository;
    }

maven 中找一下,在pom.xml中加入即可解决
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc/2.1.5.RELEASE


        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <version>2.1.5.RELEASE</version>
        </dependency>

其他问题我是参照这个文章的

转载于:https://www.jianshu.com/p/999678a760fb

猜你喜欢

转载自blog.csdn.net/weixin_34124939/article/details/91320902