Использование @Autowired с AspectJ и Springboot
Я хочу использовать аннотацию @Autowired в "аспект», Я хочу внедрить хранилище в моем аспекте, но когда я пытаюсь вызвать метод моего класса с автопроводкой, возникает исключение NullPointException.
@Aspect
public class AspectSecurity {
@Autowired
private UserRepository userRepository;
@After("execution(public * dash.*.*Controller.*(..))")
public void authentication(JoinPoint jp) throws UnauthorizedException {
System.out.println("SECURITY !");
System.out.println(userRepository.findAll().toString());
}
}
Я уже пытался добавить@Component
выше моего аспекта класса, но у меня та же ошибка.
Если я нене использовать класс аспектов, но@Controller
Я могу назвать свой репозиторий без проблем.
Некоторая документация говорит о весенней конфигурации с файлами XML, но с весенней загрузкой я неэти файлы
Вот часть моего pom.xml, которая вызывает плагин aspectJ:
org.codehaus.mojo
aspectj-maven-plugin
1.4
true
1.6
1.6
ignore
${compiler.version}
UTF-8
false
org.springframework
spring-aspects
compile
test-compile
org.aspectj
aspectjrt
${aspectj.version}
org.aspectj
aspectjtools
${aspectj.version}
Вот мой класс Application:
package dash;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Вот класс Controller, который называется аспектом:
package dash.user;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import dash.GenericController;
@Controller
@RequestMapping("/user")
public class UserController extends GenericController {
@Autowired
private UserRepository repository;
@RequestMapping("/findAll")
public @ResponseBody User create(
@RequestParam(value="login", required=true) String login,
@RequestParam(value="password", required=true) String password) {
System.out.println(login);
System.out.println(password);
System.out.println("Users found with findAll():");
System.out.println("-------------------------------");
for (User user : repository.findAll()) {
System.out.println(user);
}
return repository.findOne("root");
}
}
Примечание: я уже пытался добавить@EnableAspectJAutoProxy
выше моего класса приложения
Спасибо за вашу помощь