【发布时间】:2014-07-08 14:29:59
【问题描述】:
我的目标是在我所有的命令处理程序的 handle 方法上编织一些自定义方面。
我的自定义方面:
@Aspect
@Component
class EventProcessor @Autowired()(private val eventRepository: EventRepository) {
@Before("execution(* com.mypackage.*.application.commands.*.*(..))")
def listen() {
DomainEventPublisher.instance().subscribe(new DomainEventSubscriber[Event] {
def handleEvent(domainEvent: Event) {
eventRepository.save(domainEvent)
}
def subscribedToEventType = {
classOf[Event]
}
})
}
}
commandHandler 的一个例子:
trait CommentBlog {
def handle(command: MyCommand): ValidationNel[Failure, Unit]
}
当自定义方面在运行时编织时,整体效果很好。 对于生产,我希望它在编译时被编织,所以我使用了一个很棒的plugin 来实现它。
但是,我在运行时收到由此错误引起的NoAspectBoundException:
java.lang.NoSuchMethodError: .....EventProcessor: method <init>()V not found
这个方法 init 到底是什么?可能的根本原因是什么?
【问题讨论】:
-
不知道关于AOP,但看起来插件根本找不到
EventProcessor的默认构造函数。 -
但是插件在编译时成功地在我的类上编织了
@Transactional方面。