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

com.github.dreamroute.locker.anno.LockerConfig Maven / Gradle / Ivy

Go to download

Parent pom providing dependency and plugin management for applications built with Maven

The newest version!
package com.github.dreamroute.locker.anno;

import com.github.dreamroute.locker.interceptor.LockerInterceptor;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.NonNull;

/**
 * 描述:乐观锁配置类
 *
 * @author w.dehi.2022-02-17
 */
public class LockerConfig implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, @NonNull BeanDefinitionRegistry registry) {
        MergedAnnotation anno = importingClassMetadata.getAnnotations().get(EnableLocker.class);
        String versionColumn = anno.getString("versionColumn");
        boolean failThrowException = anno.getBoolean("failThrowException");
        LockerInterceptor lockerInterceptor = new LockerInterceptor(versionColumn, failThrowException);

        // 注册locker
        DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) registry;
        beanFactory.registerSingleton("lockerInterceptor", lockerInterceptor);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy