0

I have a class looking like this:

@Route(value = "dashboard", layout = MainView::class)
@PageTitle("Dashboard")
class DashboardView : VerticalLayout() {
    @Autowired
    private lateinit var someService: someService

    init {
        val grids = HorizontalLayout()
        grids.justifyContentMode = FlexComponent.JustifyContentMode.CENTER
        grids.alignItems = FlexComponent.Alignment.CENTER

        // initialize some grids with data from someService

        grids.setSizeFull()

        add(grids)
        setSizeFull()
        justifyContentMode = FlexComponent.JustifyContentMode.CENTER
        alignItems = FlexComponent.Alignment.CENTER
    }

    companion object {
        const val VIEW_NAME = "Dashboard"
    }
}

someService is some class annotated with Spring @Service annotation which injects someRepository to access database data.

The problem is that someService cannot be initialized before init block called and seems to be null.

I use Spring version 3.0.2 and Vaadin version 23.

I tried some tricks with @SpringView or @SpringComponent annotations, bit still have no idea how to inject this service and make it visible from my UIView init block.

Someone
  • 131
  • 3
  • 2
    Use constructor injection. Keep in mind Spring (Boot?) 3 is not compatible with Vaadin 23 – Knoobie Feb 24 '23 at 17:32
  • Use `@PostConstruct` or do your work in `onAttach` – cfrick Feb 24 '23 at 19:39
  • 1
    Does this answer your question? [@Autowired bean is null when referenced in the constructor of another bean](https://stackoverflow.com/questions/6335975/autowired-bean-is-null-when-referenced-in-the-constructor-of-another-bean) – cfrick Feb 24 '23 at 19:41

0 Answers0