我有一个带有抽象方法的抽象类@Asynchronous
public abstract void runAsync();我@Async在 Spring Async not work oncontroller's Abstract super class method中找到了这个答案问题是,runAsync如果我在实现中重写这个方法,它会是异步的吗?或者我@Asynchronous只需要在实现时进行注释?
1 回答

元芳怎么了
TA贡献1798条经验 获得超7个赞
默认情况下,注释不会被继承。@Inherited仅当注释在注释定义中具有属性时,注释才会被继承。现在看一下@Async注释定义:
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Async
Async
注解没有属性 @Inherited
,因此不会被子类继承。在这种情况下,您需要@Async
在子类重写方法中显式指定以使其起作用。
编辑:javax.ejb.Asynchronous
也没有@Inherited
属性
@Target(value={METHOD,TYPE})
@Retention(value=RUNTIME)
public @interface Asynchronous
因此,在 的情况下@Asynchronous,方法重写情况下的行为@Asynchronous将与上面提到的相同。
添加回答
举报
0/150
提交
取消