【问题标题】:Spring Boot @Service annotation in extended class扩展类中的 Spring Boot @Service 注解
【发布时间】:2020-02-17 13:26:52
【问题描述】:

嗨,我有 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 

【问题讨论】:

标签: java spring spring-boot javabeans autowired


【解决方案1】:

来自Spring Framework Javadoc@Service注解:

@Service 定义如下:

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

@Service 注释未使用@Inherited 注释进行标记。这意味着这个注解不会自动从标有它的超类继承到子类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    相关资源
    最近更新 更多