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; import com.kx.utils.idempotent.impl.RedisTokenCache; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.AutoConfigureAfter; 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 */ @ComponentScan(Const.BASE_PACKAGE + ".idempotent") @AutoConfigureAfter(RedisAutoConfiguration.class) @Slf4j public class IdempotentAutoConfiguration { @Bean @ConditionalOnMissingBean({RedisTokenCache.class}) 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(); } }