我只想实现一个简单的事情 - 创建日志记录方面,它应该挂钩每个方法以便能够打印参数。该方面如下所示:
@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() + " *****");
}
}
事情是,它使我的bean有一些奇怪的代理,然后类型不匹配。我收到以下错误:
引起: org.springframework.beans.factory.BeanNotOfRequiredTypeException:Bean 命名' downloadController'预计将是类型 ' my.package.controllers.DownloadController'但是 实际上是' com.sun.proxy。$ Proxy60'
下载控制器很简单@Component
,它是一个JavaFX控制器。
@Component
@Slf4j
public class DownloadController implements Initializable {
@FXML
private Label speedLabel;
@FXML
private Label appNameLabel;
@FXML
private ProgressBar downloadProgressBar;
@FXML
private Button cancelButton;
如果删除方面类,一切都会顺利进行。任何提示?
更新:我正在设置JavaFX自动装配如下:
@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();
}
更新:我在https://github.com/mejmo/aspect-javafx-issue上传了示例项目。