All Downloads are FREE. Search and download functionalities are using the official Maven repository.

love.keeping.starter.web.config.LockAutoConfiguration Maven / Gradle / Ivy

The newest version!
package love.keeping.starter.web.config;

import love.keeping.starter.common.locker.LockBuilder;
import love.keeping.starter.web.annotations.locker.EnableLock;
import love.keeping.starter.web.annotations.locker.LockType;
import love.keeping.starter.web.components.locker.DefaultLockBuilder;
import love.keeping.starter.web.components.redis.locker.RedisLockBuilder;
import java.util.Map;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

public class LockAutoConfiguration implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata metadata) {
        Map annotationAttributes = metadata
            .getAnnotationAttributes(EnableLock.class.getName());

        LockType type = (LockType) annotationAttributes.get("type");
        if (type == LockType.REDIS) {
            return new String[]{RedisLockConfiguration.class.getName()};
        }

        return new String[]{LockConfiguration.class.getName()};
    }

    public static class LockConfiguration {

        @Bean
        public LockBuilder lockBuilder() {
            return new DefaultLockBuilder();
        }
    }

    public static class RedisLockConfiguration {

        @Bean
        public LockBuilder lockBuilder() {
            return new RedisLockBuilder();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy