Spring io @Autowired: The blank final field may not have been initialized

Having @Autowired and final on a field are contradictory.

The latter says: this variable has one and only one value, and it’s initialized at construction time.

The former says: Spring will construct the object, leaving this field as null (its default value). Then Spring will use reflection to initialize this field with a bean of type WorkspaceRepository.

If you want final fields autowired, use constructor injection, just like you would do if you did the injection by yourself:

@Autowired
public WorkspaceController(WorkspaceRepository repository) {
    this.repository = repository;
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)