[英]Interceptor on super method in CDI 1.0/JEE6
In the following case, 在以下情况下,
public class Base {
@Transactional
public void doSave() {
// ...
}
}
public class Inherited extends Base {
public void someMethod() {
super.doSave();
}
@Override
public void doSave() {
super.doSave();
}
}
If I add the @Transactional
annotation to Inherited.someMethod
, the interceptor gets called without issue. 如果将
@Transactional
批注添加到Inherited.someMethod
,则拦截器将被调用而不会出现问题。
However, without the annotation on the inherited class, the interceptor does not get involved in the call to the super class from Inherited.someMethod()
. 但是,如果在继承的类上没有注释,则拦截器不会参与从
Inherited.someMethod()
对超类的调用。
Furthermore, calling Inherited.doSave()
does not seem to get the interceptor invoked either. 此外,调用
Inherited.doSave()
似乎也不会调用拦截器。 I would have expected the annotation on the superclass to be also valid on the subclass. 我希望超类上的注释在子类上也有效。 Is this not the expected behaviour?
这不是预期的行为吗?
I am using Apache DeltaSpike for the @Transactional
annotation and this is being deployed as a war in an ear (technically as a jar in a war in an ear). 我正在对
@Transactional
注释使用Apache DeltaSpike,并且将其部署为耳战(技术上是部署为耳战)。 However, this may not be relevant as trying with a custom interceptor shows the same behaviour. 但是,这可能不相关,因为尝试使用自定义拦截器会显示相同的行为。
This is JBoss EAP 6.3.0 Alpha in case its relevant. 如果相关的话,这是JBoss EAP 6.3.0 Alpha。
This is expected. 这是预期的。 Interceptors are only applied if the object is managed.
仅在管理对象时才应用拦截器。 When you you write it this way with inheritence, it's not applied as it's not part of a call stack that CDI is aware of.
当您使用继承方式编写它时,由于它不是CDI知道的调用堆栈的一部分,因此不会应用它。 You would need to inject
Base
into your class and call Base.doSave
您需要将
Base
注入到您的类中并调用Base.doSave
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.