0

嗨,我有 BaseClass,它包含 @Service 注释。我想从这个类扩展我的所有类但是在 MyExtendedClass 中,@Autowired 或其他方面的内容在我将 @Service 属性添加到我的 ExtendedClass 之前不起作用。为什么这是必要的?有另一种避免重复属性的方法?我想做的是将我所有的属性都放到基类中。

@Service
public class MyBase {
    public MyBase {
    }
}

//Normally it doesnt have @Service annotation but not work 
public class MyExtendedClass extends MyBase 
4

1 回答 1

2

来自Spring Framework Javadoc上的@Service注释:

@Service定义如下:

@Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
@Component
public @interface Service

@Service注释没有标注@Inherited注释。这意味着这个注解不会自动从标有它的超类继承到子类。

于 2019-10-21T13:18:39.163 回答