From 2621c6dedce5e286c21ef1c07b3858d6db69ef1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=96=87=E8=B1=AA?= <980287353@qq.com> Date: Wed, 18 Sep 2024 16:47:29 +0800 Subject: [PATCH] =?UTF-8?q?perf=EF=BC=9A=E5=8F=AF=E4=BB=A5=E4=B8=8D?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0TsAuthorityHandler=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/service/cache/TsCacheTimedHandler.java | 2 +- .../tiesheng/web/config/role/RoleAuthorityAspect.java | 2 ++ .../web/config/role/RoleAuthorityCreator.java | 11 ++++------- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/springboot-util/src/main/java/com/tiesheng/util/service/cache/TsCacheTimedHandler.java b/springboot-util/src/main/java/com/tiesheng/util/service/cache/TsCacheTimedHandler.java index ce99de0..7a32d85 100644 --- a/springboot-util/src/main/java/com/tiesheng/util/service/cache/TsCacheTimedHandler.java +++ b/springboot-util/src/main/java/com/tiesheng/util/service/cache/TsCacheTimedHandler.java @@ -10,7 +10,7 @@ import java.util.Set; import java.util.stream.Collectors; @Configuration -@ConditionalOnMissingBean(value = TsCacheHandler.class, ignored = {TsCacheTimedHandler.class, TsCacheTimedHandler.class}) +@ConditionalOnMissingBean(value = TsCacheHandler.class, ignored = {TsCacheTimedHandler.class}) public class TsCacheTimedHandler implements TsCacheHandler { private static volatile TimedCache timedCache; diff --git a/springboot-web/src/main/java/com/tiesheng/web/config/role/RoleAuthorityAspect.java b/springboot-web/src/main/java/com/tiesheng/web/config/role/RoleAuthorityAspect.java index 15d8dd0..6078a3f 100644 --- a/springboot-web/src/main/java/com/tiesheng/web/config/role/RoleAuthorityAspect.java +++ b/springboot-web/src/main/java/com/tiesheng/web/config/role/RoleAuthorityAspect.java @@ -15,6 +15,7 @@ import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -24,6 +25,7 @@ import java.util.stream.Collectors; @Aspect @Component +@ConditionalOnBean(value = TsAuthorityHandler.class) public class RoleAuthorityAspect { @Resource diff --git a/springboot-web/src/main/java/com/tiesheng/web/config/role/RoleAuthorityCreator.java b/springboot-web/src/main/java/com/tiesheng/web/config/role/RoleAuthorityCreator.java index ce97d79..81fb0d1 100644 --- a/springboot-web/src/main/java/com/tiesheng/web/config/role/RoleAuthorityCreator.java +++ b/springboot-web/src/main/java/com/tiesheng/web/config/role/RoleAuthorityCreator.java @@ -5,12 +5,13 @@ import cn.hutool.core.date.DateUtil; import com.tiesheng.annotation.role.RoleAuthority; import com.tiesheng.util.service.role.TsAuthorityHandler; import org.springframework.aop.support.AopUtils; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Date; @@ -18,19 +19,15 @@ import java.util.List; import java.util.Map; @Service +@ConditionalOnBean(value = TsAuthorityHandler.class) public class RoleAuthorityCreator implements ApplicationListener { - @Autowired(required = false) + @Resource TsAuthorityHandler tsAuthorityHandler; @Override public void onApplicationEvent(ContextRefreshedEvent event) { - - if (tsAuthorityHandler == null) { - return; - } - ApplicationContext applicationContext = event.getApplicationContext(); Map beansOfType = applicationContext.getBeansWithAnnotation(RoleAuthority.class);