Spring autowired bean for @Aspect aspect is null

后端 未结 9 1078
离开以前
离开以前 2020-11-29 03:42

I have the following spring configuration:





        
9条回答
  •  臣服心动
    2020-11-29 04:13

    For Spring Boot to use @Autowired with AspectJ I have found the following method. In configuration class add your aspect:

    @Configuration
    @ComponentScan("com.kirillch.eqrul")
    public class AspectConfig {
    
        @Bean
        public EmailAspect theAspect() {
            EmailAspect aspect = Aspects.aspectOf(EmailAspect.class);
            return aspect;
        }
    
    }
    

    Then you can successfully autowire your services in your aspect class:

    @Aspect
    public class EmailAspect {
    
        @Autowired
        EmailService emailService;
    

提交回复
热议问题