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 2ca2ad0e..0c09925b 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 00000000..d6a8f9b5 --- /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 14658c39..50f0267b 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