Lock4jAutoConfiguration.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package jnpf.config;
  2. import com.baomidou.lock.aop.LockAnnotationAdvisor;
  3. import com.baomidou.lock.aop.LockInterceptor;
  4. import org.springframework.aop.Pointcut;
  5. import org.springframework.aop.aspectj.AspectJExpressionPointcut;
  6. import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  7. import org.springframework.context.annotation.Bean;
  8. import org.springframework.context.annotation.Configuration;
  9. import org.springframework.core.Ordered;
  10. /**
  11. * Lock4jAop开关
  12. */
  13. @Configuration(proxyBeanMethods = false)
  14. public class Lock4jAutoConfiguration {
  15. @Bean
  16. @ConditionalOnProperty(prefix = "lock4j.aop", name = "enabled", havingValue = "true", matchIfMissing = false)
  17. public LockAnnotationAdvisor lockAnnotationAdvisor(LockInterceptor lockInterceptor) {
  18. return new LockAnnotationAdvisor(lockInterceptor, Ordered.HIGHEST_PRECEDENCE){
  19. private final AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
  20. {
  21. pointcut.setExpression("within(jnpf..*) && @annotation(com.baomidou.lock.annotation.Lock4j)");
  22. }
  23. @Override
  24. public Pointcut getPointcut() {
  25. return pointcut;
  26. }
  27. };
  28. }
  29. @Bean
  30. @ConditionalOnProperty(prefix = "lock4j.aop", name = "enabled", havingValue = "false", matchIfMissing = true)
  31. public LockAnnotationAdvisor lockAnnotationAdvisor2(LockInterceptor lockInterceptor) {
  32. return new LockAnnotationAdvisor(lockInterceptor, Integer.MIN_VALUE) {
  33. private final AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
  34. {
  35. this.pointcut.setExpression("within(jnpf.config.*) && @annotation(com.baomidou.lock.annotation.Lock4j)");
  36. }
  37. public Pointcut getPointcut() {
  38. return this.pointcut;
  39. }
  40. };
  41. }
  42. }