Spring @带有Java继承的RequestScope注释行为

Spring @带有Java继承的RequestScope注释行为,spring,spring-boot,inheritance,spring-annotations,requestscope,Spring,Spring Boot,Inheritance,Spring Annotations,Requestscope,假设我们有一节课 @RequestScope public abstract class A { int a; } 以及扩展上述类的另一个类 @Service public class B extends A { public int getA () { return a; } } 这个B类的变量(从A扩展而来)是请求范围的变量吗 UPD 上面说,我正在检查spring代码 /** *默认作用域名称的常量:{@code”“},相当于singleton *状态,除非

假设我们有一节课

@RequestScope 
public abstract class A {
    int a;
}
以及扩展上述类的另一个类

@Service 
public class B extends A {
    public int getA () { return a; }    
}
这个B类的变量(从A扩展而来)是请求范围的变量吗

UPD

上面说,我正在检查spring代码

/**
*默认作用域名称的常量:{@code”“},相当于singleton
*状态,除非从父bean定义重写(如果适用)。
*/
公共静态最终字符串范围_DEFAULT=“”

而且

((AbstractBeanDefinition)((AnnotationConfigEmbeddedWebApplicationContext) ctx).
getBeanDefinition("b")).scope
返回
“singleton”

但是如果我用
@RequestScope
标记B类,则此属性将更改为
“”


我假设是
sigleton
再次

是可继承的,注释必须标记为
@Inherited
注释。查看
@RequestScope
的源代码:

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Scope(WebApplicationContext.SCOPE_REQUEST)
public @interface RequestScope {

    /**
     * Alias for {@link Scope#proxyMode}.
     * <p>Defaults to {@link ScopedProxyMode#TARGET_CLASS}.
     */
    @AliasFor(annotation = Scope.class)
    ScopedProxyMode proxyMode() default ScopedProxyMode.TARGET_CLASS;

}
@Target({ElementType.TYPE,ElementType.METHOD})
@保留(RetentionPolicy.RUNTIME)
@记录
@作用域(WebApplicationContext.Scope\u请求)
public@interface-RequestScope{
/**
*{@link Scope#proxyMode}的别名。
*默认为{@link ScopedProxyMode#TARGET_CLASS}。
*/
@别名(注释=Scope.class)
ScopedProxyMode proxyMode()默认ScopedProxyMode.TARGET_类;
}

它没有标记为继承的
@Inherited
。因此它不影响子类。这意味着示例中类
B
的变量不是请求范围的变量,而是默认情况下的单例变量。您可以找到有关预定义注释的更多详细信息

如果我们看一下lombok getter注释,它也没有用@Inherited annotation标记,但似乎有效。@swayamraina因为lombok getter注释标记方法,而不是类。子类继承了应用了所有注释的方法。@swayamraina尝试在子类中重写用lombok getter标记的方法,您将看到