本文主要是介绍SpringBoot3 + SpringSecurity6 + JWT,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
相关链接
Spring Security mvnrepository
1. pom 引入
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.27</version>
</dependency>
2. 创建 UserBO 实现 UserDetails(spring security 中)
public class UserBO implements UserDetails {private String password;private String username;private List<GrantedAuthority> authorities;private boolean accountNonExpired;private boolean accountNonLocked;private boolean credentialsNonExpired;private boolean enabled;
}
3. 创建 service 实现 UserDetailsService
@Service
public class UserDetailsDetailsService implements IUserDetailsService {@AutowiredIAccountInfoService accountInfoService;@Overridepublic UserBO loadUserByUsername(String username) throws UsernameNotFoundException {AccountInfo ai = accountInfoService.findByUsername(use
这篇关于SpringBoot3 + SpringSecurity6 + JWT的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!