Deploying a Vaadin 24 application to tomcat 10

Are there any instructions on how to do this from start to finish? I ask because I’ve been trying to follow the documentation at https://vaadin.com/docs/latest/integrations/spring/spring-mvc and I’m a bit confused.

Specifically I’m getting the error: org.apache.catalina.core.StandardContext.startInternal Error during ServletContainerInitializer processing. jakarta.servlet.ServletException: Failed to instantiate WebApplicationInitializer class

and:

Caused by: java.lang.NoSuchMethodException: com.rana.web.Application.()

My constructor is passing in property file such as Application(@Value(“${some.property.name}”) String propertyName, …)

I do see on that page that I need to create a WebApplicationInitializer class but it also says I need to register configuration classes but I’m not sure what that means outside of the application I have running in my IDE. Same with the scoping and routes on that same Vaadin page.

All in all is there a sample project somewhere on git, a walk through, etc. that I can follow?

Vaadin is not really involved here. Just follow the spring boot steps https://www.baeldung.com/spring-boot-war-tomcat-deploy and make sure to build your war with production mode

I’ve gone through that but I’m not very familiar with the actual deployment of a spring app on tomcat. I’m much more on the coding side. Specifically do you have any idea on how to get past the noSuchMethod exception on Application.init() if I’m using it to load properties files. The error is correct becuase there is no init() method, instead it’s an init(…).

Just a guess: don’t do it. Spring Boot’s application class is not really suited to have a constructor in my mind

The mentioned method is the default constructor.
Servlet listeners must have a public zero argument constructor

Maybe this can help you https://www.baeldung.com/spring-boot-servlet-initializer

But then how do you load application.properties values? I tried property injection and that fails.

You can inject them anywhere just not in the Application.java

So I’ve tried to inject the values through properties injecting in the view and I’m getting null. But also how do you do it if you need some values on server startup? I tried to add a custom class that the Application class calls but similarly I could not load the application properties values…

Biased opinion: don’t deploy a spring boot application to a tomcat and use the build-in application server, life is 500% better

I’m familiar with how to link apache and tomcat. How do you do it with the built-in application server? I assume it’s using Jetty but I’m not that familiar with it…

Spring boot uses tomcat by default… what do you mean with linking them? Using Apache httpd server in front of your Tomcat as reverse proxy? If yes: exactly the same, nothing changes (except AJP, this have to be enabled / configured in boot)

Is there any documentation anywhere on how to do this?

And yes exactly that

The deployment with a reverse proxy is not my forte. My knowledge in this area is pretty weak. I would love to use the embedded server but I just don’t know much there either. I thought it used Jetty, I didn’t realize it used Tomcat.

You can use any documentation from Apache for proxying, there are no things specific for boot, it just works as tomcat for you if you run your fat jar with java -jar it opens a port at 8080 - which is the embedded tomcat

So in essence it’s just an embedded tomcat server. How do you configure say the catalina_opts and so on in tomcat? Add environment variables like setenv.sh in the tomcat conf folder? Possibly set it up as a service in linux? Or things of that nature?

https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html everything is good documented

Catalina ops are not really needed, you can pass java ops to the process

Environment Variables can be added to an application.yml next to your application and boot is resolving them on startup