Pārlūkot izejas kodu

修复角色权限注解失效问题

RuoYi 5 gadi atpakaļ
vecāks
revīzija
1818af2a08

+ 0 - 2
ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java

@@ -1,6 +1,5 @@
 package com.ruoyi;
 
-import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -11,7 +10,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  * @author ruoyi
  */
 @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
-@MapperScan("com.ruoyi.*.mapper")
 public class RuoYiApplication
 {
     public static void main(String[] args)

+ 13 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/spring/SpringUtils.java

@@ -1,5 +1,6 @@
 package com.ruoyi.common.utils.spring;
 
+import org.springframework.aop.framework.AopContext;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
@@ -98,4 +99,16 @@ public final class SpringUtils implements BeanFactoryPostProcessor
     {
         return beanFactory.getAliases(name);
     }
+
+    /**
+     * 获取aop代理对象
+     * 
+     * @param invoker
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T getAopProxy(T invoker)
+    {
+        return (T) AopContext.currentProxy();
+    }
 }

+ 20 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ApplicationConfig.java

@@ -0,0 +1,20 @@
+package com.ruoyi.framework.config;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+
+/**
+ * 程序注解配置
+ *
+ * @author ruoyi
+ */
+@Configuration
+// 表示通过aop框架暴露该代理对象,AopContext能够访问
+@EnableAspectJAutoProxy(exposeProxy = true)
+// 指定要扫描的Mapper类的包的路径
+@MapperScan("com.ruoyi.*.mapper")
+public class ApplicationConfig
+{
+
+}

+ 3 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java

@@ -13,6 +13,7 @@ import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.text.Convert;
 import com.ruoyi.common.exception.BusinessException;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.spring.SpringUtils;
 import com.ruoyi.system.domain.SysRole;
 import com.ruoyi.system.domain.SysRoleDept;
 import com.ruoyi.system.domain.SysRoleMenu;
@@ -110,7 +111,7 @@ public class SysRoleServiceImpl implements ISysRoleService
     @Override
     public List<SysRole> selectRoleAll()
     {
-        return selectRoleList(new SysRole());
+        return SpringUtils.getAopProxy(this).selectRoleList(new SysRole());
     }
 
     /**
@@ -315,6 +316,7 @@ public class SysRoleServiceImpl implements ISysRoleService
     {
         return roleMapper.updateRole(role);
     }
+
     /**
      * 取消授权用户角色
      *