I want to use @Autowired annotation into an "Aspect". I want to inject a repository in my aspect but when I try to call a method of my autowired class a NullPointE
Here is my configuration:
@Component
@Aspect
public class WebControllerAop {
@Autowired
private PersonService personService;
//匹配com.zkn.learnspringboot.web.controller包及其子包下的所有类的所有方法
@Pointcut("execution(* com.zkn.learnspringboot.web.controller..*.*(..))")
public void executeService(){
}
}
@RestController
@EnableAutoConfiguration
@ComponentScan
public class FirstExample {
public static void main(String[] args) {
SpringApplication.run(FirstExample.class, args);
}
}
org.springframework.boot
spring-boot-starter-parent
1.4.0.RELEASE
org.springframework.boot
spring-boot-starter-aop
It can work well.