SpringInstantiator used even though views are not spring beans

Hi,

I was a bit surprised today when i saw a stacktrace in our app and noticed that SpringInstantiator creates the view instances (i.e. the route targets). Is this expected also when the views are not Spring beans? We purposely opted to not have our views spring-managed. Guessing this is coming from the vaadin-spring-boot-starter dependency, which i thought was mandatory to get Vaadin working in a spring-boot app ?

    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:318)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:186)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1354)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:561)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:320)
    at com.vaadin.flow.spring.SpringInstantiator.getOrCreate(SpringInstantiator.java:126)
    at com.vaadin.flow.di.Instantiator.createRouteTarget(Instantiator.java:136)
    at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.lambda$getRouteTarget$1(AbstractNavigationStateRenderer.java:132)

Yes, this is expected. That is indeed coming from using the Spring integration.

Is it needed? I can imagine a significant overhead of Spring’s ConstructorResolver.autowireConstructor trying to instantiate a simple class vs Vaadin’s ReflectTools.createInstance()

All Views are by default spring beans. (When spring is used)

It makes me wonder whether i even need vaadin-spring-boot-starter then? We don’t autowire dependencies into our views.

Using Spring and/or Spring Boot is not mandatory. Take a look at this starter project GitHub - vaadin/skeleton-starter-flow: Default project template for Vaadin for example

Sure, but our application is a spring-boot app, and uses the spring-security extensions from Vaadin. Given that i think using the vaadin spring-boot starter is a must.

I’m not saying that things don’t work, just surprised to learn that the route targets are going through the whole spring bean instantiation machinery whereas they really don’t need to.

So you want Spring Security but not Spring DI?

Spring DI is not used in our views indeed. But we do use @RolesAllowed so i guess spring needs to manage the route targets as beans somehow anyway.

I can imagine a significant overhead of Spring’s ConstructorResolver.autowireConstructor trying to instantiate a simple class vs Vaadin’s ReflectTools.createInstance()
I wouldn’t worry about something like that unless you measure a problem with it. How many views do you have? I’m guessing no more than a few hundred, maybe a thousand tops?