Vaadinn + Spring (Making rest services work alongside vaadin views)

Hello, I’m facing challenges with the integration of Vaadin and Spring Boot. I’m specifically encountering issues because, in most cases, the code for Vaadin views is written within the constructor body, where the Spring services are not yet available. As a result, I’m unable to utilize the injected services during view initialization. Could you please provide guidance on how to overcome this limitation and ensure that the Spring services are accessible within the Vaadin view constructors?

Inject them to the constructor.

That’s the issue. I’m doing that but it’s not just working I don’t get why.
Seems the services aren’t yet available before the constructor is being invoked

I doubt that. Please show us what you do

This is my view
@PageTitle("List") @Route(value = "") public class ListView extends VerticalLayout { private ListService listService; public ListView(ListService listService) { this.listService = listService; ... // my code goes in here }

Now, when ever I try to call a service in that service I get a null pointer

I think it’s not the best practice but that’s why I am asking

Sorry but I can’t believe that something so fundamental like constructor injection of spring is broken :sweat_smile: especially since constructor injection is the recommended way. If the bean can’t be found, the whole application won’t start, so I would say not the service is null, but something else

I myself I’m wondering whats the issue but that’s what brings me here.

What’s the best way in your opinion to do this as it’s my very first vaadin app

I personally build views inside PostConstruct, before/afterEnter callbacks or onAttach. But that won’t solve your problem, because something looks sus that you can’t inject a service / the service doesn’t break the app

I’ll try that