gpt4 book ai didi

java - 子类实现上的@Required注解

转载 作者:行者123 更新时间:2023-12-02 07:08:56 26 4
gpt4 key购买 nike

我遇到一种情况,我想仅在 parentClass 的某些实现上将 setter 方法注释为 @Required。但是,除非我注释基类 Spring 不会将该方法识别为配置中所需的方法(也就是说,如果该字段不存在,我不会得到“缺少必需的属性:foo”。下面是我尝试使用的代码:

public abstract class parentClass {
public abstract void setFoo(Object foo);
}

public abstract class childClass extends parentClass {
@Override
@Required
public void setFoo(Object foo) {
//setter code
}
}

我在这里做错了什么?是否可以仅为某些子类指定注释?

最佳答案

不继承类以外的项目上的注释。请参阅@Inherited Javadoc

Note that this meta-annotation type has no effect if the annotated type is used to annotate anything other than a class. Note also that this meta-annotation only causes annotations to be inherited from superclasses; annotations on implemented interfaces have no effect.

我不确定 JSR 305 处理器如何管理这个技巧。

关于java - 子类实现上的@Required注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15770735/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com