IdempotentAutoConfiguration.java 1.4 KB
Newer Older
1 2 3 4 5 6 7
package com.kx.config;

import com.kx.Const;
import com.kx.utils.idempotent.TokenCache;
import com.kx.utils.idempotent.TokenValueRequestHolder;
import com.kx.utils.idempotent.impl.DefaultTokenValueRequestHolder;
import com.kx.utils.idempotent.impl.InMemoryTokenCache;
8
import com.kx.utils.idempotent.impl.RedisTokenCache;
9
import lombok.extern.slf4j.Slf4j;
10
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
11 12 13 14 15 16 17 18 19
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

/**
 * 幂等工具自动配置类
 * @author kongxiang
 */
20 21
@ComponentScan(Const.BASE_PACKAGE + ".idempotent")
@AutoConfigureAfter(RedisAutoConfiguration.class)
22 23 24
@Slf4j
public class IdempotentAutoConfiguration {
    @Bean
25
    @ConditionalOnMissingBean({RedisTokenCache.class})
26 27 28 29 30 31 32 33 34 35 36 37 38
    public InMemoryTokenCache inMemoryTokenCache(){
        log.info("加载默认TokenCache: {}",InMemoryTokenCache.class);
        return new InMemoryTokenCache();
    }

    @Bean
    @ConditionalOnMissingBean(TokenValueRequestHolder.class)
    public DefaultTokenValueRequestHolder defaultTokenValueRequestHolder(){
        log.info("加载默认TTokenValueRequestHolder: {}",DefaultTokenValueRequestHolder.class);
        return new DefaultTokenValueRequestHolder();
    }

}