使用aop

时间:2018-04-26 12:32:36

标签: spring spring-boot spring-aop

我使用spring boot2,spring 5

对于我的控制器,我有这些包

com.murphys.lcm.controller.mvc
com.murphys.lcm.controller.rest

我想在这两个包

中为我的所有方法调用getAllAdvice方法
@Aspect
@Component
public class LogActionAspect {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Before("execution(* com.murphys.lcm.controller.*(..))")
    public void getAllAdvice(JoinPoint joinPoint){
    }
}

应用程序不再启动我有很多错误

  

org.springframework.beans.factory.BeanCreationException:错误   用name" projectionDefinitionRegistrar'创建bean。定义于   类路径资源   [组织/ springframework的/数据/休息/ webmvc /配置/ RepositoryRestMvcConfiguration.class]:   实例化bean之前的BeanPostProcessor失败;嵌套   异常是org.springframework.beans.factory.BeanCreationException:   使用名称创建bean时出错   ' org.springframework.cache.annotation.ProxyCachingConfiguration&#39 ;:   实例化bean之前的BeanPostProcessor失败;嵌套   异常是org.springframework.beans.factory.BeanCreationException:   使用名称' metaDataSourceAdvisor'创建bean时出错:无法解决   引用bean' methodSecurityMetadataSource'在设置   构造函数参数;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   用名字创建bean   ' org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration&#39 ;:   实例化bean之前的BeanPostProcessor失败;嵌套   异常是org.springframework.beans.factory.BeanCreationException:   使用名称创建bean时出错   ' org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration&#39 ;:   bean的初始化失败;嵌套异常是   java.lang.IllegalArgumentException:警告此类型不匹配   name:com.murphys.lcm.controller [Xlint:invalidAbsoluteTypeName] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:496)

     

引起:org.springframework.beans.factory.BeanCreationException:   使用名称创建bean时出错   ' org.springframework.cache.annotation.ProxyCachingConfiguration&#39 ;:   实例化bean之前的BeanPostProcessor失败;嵌套   异常是org.springframework.beans.factory.BeanCreationException:   使用名称' metaDataSourceAdvisor'创建bean时出错:无法解决   引用bean' methodSecurityMetadataSource'在设置   构造函数参数;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   用名字创建bean   ' org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration&#39 ;:   实例化bean之前的BeanPostProcessor失败;嵌套   异常是org.springframework.beans.factory.BeanCreationException:   使用名称创建bean时出错   ' org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration&#39 ;:   bean的初始化失败;嵌套异常是   java.lang.IllegalArgumentException:警告此类型不匹配   name:com.murphys.lcm.controller [Xlint:invalidAbsoluteTypeName] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:496)

     

引起:org.springframework.beans.factory.BeanCreationException:   使用名称' metaDataSourceAdvisor'创建bean时出错:无法解决   引用bean' methodSecurityMetadataSource'在设置   构造函数参数;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   用名字创建bean   ' org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration&#39 ;:   实例化bean之前的BeanPostProcessor失败;嵌套   异常是org.springframework.beans.factory.BeanCreationException:   使用名称创建bean时出错   ' org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration&#39 ;:   bean的初始化失败;嵌套异常是   java.lang.IllegalArgumentException:警告此类型不匹配   name:com.murphys.lcm.controller [Xlint:invalidAbsoluteTypeName] at   org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:378)         引起:org.springframework.beans.factory.BeanCreationException:   使用名称创建bean时出错   ' org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration&#39 ;:   实例化bean之前的BeanPostProcessor失败;嵌套   异常是org.springframework.beans.factory.BeanCreationException:   使用名称创建bean时出错   ' org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration&#39 ;:   bean的初始化失败;嵌套异常是   java.lang.IllegalArgumentException:警告此类型不匹配   name:com.murphys.lcm.controller [Xlint:invalidAbsoluteTypeName] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:496)

1 个答案:

答案 0 :(得分:2)

试试这个

@Before("execution(* com.murphys.lcm.controller.*.*Controller*.*(..))")

将获得所有控制器(假设您的控制器名称中包含Controller)

刚刚测试过并且工作