springboot+springsecurity+mybatis+thymeleaf实现用户登录和权限过程中的坑

1.折腾了两天的springboot+springsecurity+mybatis+thymeleaf集成,参考博客如下

springboot+mybatis+SpringSecurity 实现用户角色数据库管理https://blog.csdn.net/u012373815/article/details/54633046
2.这篇博客写的很详细,在此感谢”双斜杠少年“博主,但是里边有一个小坑,提醒一下,就是mybatis的mapper.xml文件命名必须和对应的dao一样,如文中UserDao.java对应的xml文件应该命名为UserDao.xml,不知为何作者写成了UserDaomapper.xml
3.在换成数据库方式读取用户信息时,此时一定要即可,数据库中用户的角色role一定要写成ROLE_ADMIN的形式,前边的ROLE_是必须得加的!!!
4.在.antMatchers("/manager/**").hasRole(“ADMIN”),配置是,一定不能加ROLE_,因为springsecurity底层会自动去掉数据库中的ROLE_,如果在这里仍然加这个前缀,在启动时会报错如下:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘springSecurityFilterChain’ defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method ‘springSecurityFilterChain’ threw exception; nested exception is java.lang.IllegalArgumentException: role should not start with ‘ROLE_’ since it is automatically inserted. Got ‘ROLE_ADMIN’

你可能感兴趣的:(springboot+springsecurity+mybatis+thymeleaf实现用户登录和权限过程中的坑)