问题
I just want to achieve one simple thing - to create logging aspect, which should hook on every method to be able print arguments. The aspect looks like as following:
@Aspect
@Component
@Slf4j
public class MyLogger {
public MyLogger () {}
@AfterReturning("execution(* my.package..*.*(..))")
public void logMethodAccessAfter(JoinPoint joinPoint) {
System.out.println("***** Completed: " + joinPoint.getSignature().getName() + " *****");
}
@Before("execution(* my.package..*.*(..))")
public void logMethodAccessBefore(JoinPoint joinPoint) {
System.out.println("***** Starting: " + joinPoint.getSignature().getName() + " *****");
}
}
Thing is, it makes some strange proxy out my beans and the types then do not match. I get following error:
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'downloadController' is expected to be of type 'my.package.controllers.DownloadController' but was actually of type 'com.sun.proxy.$Proxy60'
Download controller is simple @Component
which is a JavaFX controller.
@Component
@Slf4j
public class DownloadController implements Initializable {
@FXML
private Label speedLabel;
@FXML
private Label appNameLabel;
@FXML
private ProgressBar downloadProgressBar;
@FXML
private Button cancelButton;
If I delete the aspect class, everything runs smoothly. Any hint?
UPDATE: I am setting up the JavaFX autowiring as following:
@Override
public void init() throws Exception {
SpringApplicationBuilder builder = new SpringApplicationBuilder(XAPStarterApplication.class);
builder.headless(false);
springContext = builder.run(XAPStarterApplication.args);
springContext.getAutowireCapableBeanFactory().autowireBean(this);
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/MainUI.fxml"));
fxmlLoader.setControllerFactory(springContext::getBean);
root = fxmlLoader.load();
}
UPDATE: I uploaded the sample project in https://github.com/mejmo/aspect-javafx-issue .
来源:https://stackoverflow.com/questions/45933616/cant-create-aspect-in-spring-boot