在抽象类中使用@Autowired


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

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