java - 扩展类中的 Spring Boot @Service 注解

标签 java spring spring-boot javabeans autowired

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

最佳答案

来自Spring Framework Javadoc@Service 注释上:

@Service 定义如下:

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

@Service 注释未使用 @Inherited 注释进行标记。这意味着该注解不会自动从标记有该注解的父类(super class)继承到子类。

关于java - 扩展类中的 Spring Boot @Service 注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58486589/

相关文章:

java - Gson 如何解析单个数组中的不同数据类型?

Java-如何从字符串列表创建哈希ID

java - 部署在 Heroku 上的 Spring Boot 应用程序仍然崩溃

java - Spring-Maven Project : Unsupported major.次要版本52.0顽固错误

java - com.mongodb.MongoSocketOpenException : Exception opening socket(MongoDB, docker )

java - 如何让这段代码停止在非数字的地方?

spring - 如何同时使用 Rabbit 连接缓存模式和自动声明功能?

java - 使用 PropertySourcesPlaceholderConfigurer 时如何解密属性值

java - 使用 Spring Boot 配置 Ehcache TTL 超时

java - 使用 Apache Pulsar 和 Spring Boot 自定义对象