注解表示配置信息
@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");