注解表示配置信息
@Configuration
public class TokenStoreConfig {
@Autowired,依赖注入,可选
@Autowired(required=false)
private RedisTemplate<String, Object> redisTemplate ;
@Bean @ConditionalOnProperty,什么时候创建Bean
@Bean
@ConditionalOnProperty(prefix="security.oauth2.token.store",name="type" ,havingValue="jdbc" ,matchIfMissing=false)
public JdbcTokenStore jdbcTokenStore(){
security:
oauth2:
token:
store:
type: redis
这个可以作为默认Bean
@Bean
@ConditionalOnProperty(prefix="security.oauth2.token.store",name="type" ,havingValue="redis" ,matchIfMissing=true)
public RedisTemplateTokenStore redisTokenStore(RedisConnectionFactory connectionFactory){
Assert.state(connectionFactory != null, "connectionFactory must be provided");
本文介绍如何使用Spring Boot配置OAuth2的Token存储方式,包括基于JDBC和Redis的实现。通过注解@ConditionalOnProperty根据配置文件决定使用哪种存储方式。
1168

被折叠的 条评论
为什么被折叠?



