Sources of the application with the problem: github

Problem: @Value / @Resource / @Autowired annotations do not work in @Autowired . Moreover, if @Autowired registered on the constructor, and not on the field, then it works (for example, if you pass resourcesUtil through the constructor). How to fix this problem?

PS: The class ru.blestar.ui.StartView is seen as a component / bin and is substituted into the class ru.blestar.App (this can be seen by running the application)

    1 answer 1

    You are trying to use fields in the spring bean constructor that must be initialized with spring. At the time of class creation, these fields are not yet defined. In other words, the spring first creates the instance instance and then processes the annotations.

    Pass the constructor of the StartView class to the method that will be called after the bean is uniolized (to do this, use the @PostConstruct annotation) and you will get the desired result.

     @PostConstruct public void init() { Button button = new Button(buttonText); getChildren().add(button); if (resourcesUtil == null) { log.error("ResourcesUtil is null. In class {}", getClass()); } }