Correctness28 - SpotBugsExtensionForSpringFrameWork/CS5098 GitHub Wiki

Bug Name: Field injection cannot be used for final fields

Description

"Field injection cannot be used for final fields. This type of fields can only be initialized using constructor injection."

@Service("singer")
public class Singer {
    @Autowired
    private Inspiration inspirationBean; // not final!!
    public void sing() {
        System.out.println("... " + inspirationBean.getLyric());
    }
}

Theory

simple - If any dependency is injected in the final fields, then it is considered bug pattern

Reference List

Pro Spring 5 (5th edition) - Chapter 3 (65 page)

https://stackoverflow.com/questions/34580033/spring-io-autowired-the-blank-final-field-may-not-have-been-initialized