From 085e6631c664395098e04fb1a4e9a12c7d88592f Mon Sep 17 00:00:00 2001 From: RuoYi Date: Mon, 8 Jun 2020 08:40:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E6=80=A7=E5=8C=96=E7=9A=84=E5=AE=9A?= =?UTF-8?q?=E5=88=B6=E8=87=AA=E5=8A=A8=E5=8A=A0=E8=BD=BD=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../annotation/EnableCustomConfig.java | 4 +++ ...SecurityImportBeanDefinitionRegistrar.java | 25 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 3 +-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/config/SecurityImportBeanDefinitionRegistrar.java diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableCustomConfig.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableCustomConfig.java index 2ca2ad0eb..0c09925be 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableCustomConfig.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableCustomConfig.java @@ -8,7 +8,9 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.context.annotation.Import; import org.springframework.scheduling.annotation.EnableAsync; +import com.ruoyi.common.security.config.SecurityImportBeanDefinitionRegistrar; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @@ -20,6 +22,8 @@ import org.springframework.scheduling.annotation.EnableAsync; @MapperScan("com.ruoyi.**.mapper") // 开启线程异步执行 @EnableAsync +// 自动加载类 +@Import(SecurityImportBeanDefinitionRegistrar.class) public @interface EnableCustomConfig { diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/config/SecurityImportBeanDefinitionRegistrar.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/config/SecurityImportBeanDefinitionRegistrar.java new file mode 100644 index 000000000..d6a8f9b5c --- /dev/null +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/config/SecurityImportBeanDefinitionRegistrar.java @@ -0,0 +1,25 @@ +package com.ruoyi.common.security.config; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; +import org.springframework.core.type.AnnotationMetadata; +import com.ruoyi.common.core.utils.StringUtils; + +/** + * 导入 SecurityImportBeanDefinitionRegistrar 自动加载类 + * + * @author ruoyi + */ +public class SecurityImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar +{ + @Override + public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) + { + Class aClass = ResourceServerConfig.class; + String beanName = StringUtils.uncapitalize(aClass.getSimpleName()); + BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(ResourceServerConfig.class); + registry.registerBeanDefinition(beanName, beanDefinitionBuilder.getBeanDefinition()); + + } +} diff --git a/ruoyi-common/ruoyi-common-security/src/main/resources/META-INF/spring.factories b/ruoyi-common/ruoyi-common-security/src/main/resources/META-INF/spring.factories index 14658c390..50f0267bb 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/resources/META-INF/spring.factories +++ b/ruoyi-common/ruoyi-common-security/src/main/resources/META-INF/spring.factories @@ -1,6 +1,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.ruoyi.common.security.service.UserDetailsServiceImpl,\ - com.ruoyi.common.security.handler.CustomAccessDeniedHandler,\ - com.ruoyi.common.security.config.ResourceServerConfig + com.ruoyi.common.security.handler.CustomAccessDeniedHandler