在抽象类中使用@Autowired

当我们使用_@Autowired_上setter方法,我们应该用final 关键字,这样子类便不能覆盖setter方法。否则,注解将无法正常运行。

public abstract class BallService {
     private LogRepository logRepository;
     @Autowired
     public final void setLogRepository(LogRepository logRepository) {
         this.logRepository = logRepository;
     }
}

 

posted @ 2022-05-10 17:06  君子笑而不语  阅读(329)  评论(0编辑  收藏  举报