From c8676b3040adb27d5fddf75191fe31d1855f8312 Mon Sep 17 00:00:00 2001 From: EightMonth Date: Fri, 22 Mar 2024 17:11:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B3=A8=E8=A7=A3=E7=94=9F?= =?UTF-8?q?=E6=95=88=E8=8C=83=E5=9B=B4=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/config/shiro/ShiroConfig.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java b/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java index 37966725..76cd0cdd 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java @@ -21,10 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.DependsOn; +import org.springframework.context.annotation.*; +import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.env.Environment; import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; @@ -49,6 +47,8 @@ import java.util.*; @Slf4j @Configuration +// 免认证注解 @IgnoreAuth 注解生效范围配置 +@ComponentScan(basePackages = {"org.jeecg"}) public class ShiroConfig { @Resource @@ -340,8 +340,13 @@ public class ShiroConfig { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.addIncludeFilter(new AnnotationTypeFilter(RestController.class)); - String basePackage = "org.jeecg"; // 替换为你的包路径 - Set components = provider.findCandidateComponents(basePackage); + // 获取当前类的扫描注解的配置 + Set components = new HashSet<>(); + for (String basePackage : AnnotationUtils.getAnnotation(ShiroConfig.class, ComponentScan.class).basePackages()) { + components.addAll(provider.findCandidateComponents(basePackage)); + } + + // 逐个匹配获取免认证路径 for (BeanDefinition component : components) { String beanClassName = component.getBeanClassName(); Class clazz = Class.forName(beanClassName);