𝗦𝗽𝗿𝗶𝗻𝗴 𝗕𝗼𝗼𝘁 𝗜𝘀 𝗡𝗼𝘁 𝗝𝘂𝘀𝘁 𝗮 𝗥𝗘𝗦𝗧 𝗔𝗣𝗜 𝗦𝗲𝗿𝘃𝗲𝗿

Many developers think Spring Boot only serves JSON data. They believe you must host a React or Vue app on a separate server like Vercel or AWS.

This is a mistake.

Spring Boot includes an embedded Apache Tomcat server. This means you can build full-stack applications inside a single JAR file.

Using a single JAR file gives you three main benefits:

  • Zero CORS issues: Your frontend and backend use the same port and domain.
  • Lower costs: You do not need a separate Node.js server. One Linux server or Docker container runs everything.
  • Simple deployment: One build process handles both your UI and your server.

Here are four ways to include your UI in Spring Boot:

  1. Server-Side Templating (SSR) Use Thymeleaf to render HTML on the server. You add the starter dependency to your Maven file and use a Controller to return HTML templates. It is simple and fast.

  2. Vaadin Vaadin lets you build modern web apps using only Java. You do not write JavaScript or CSS. Vaadin handles the React components in the background and serves them via Tomcat. This is great for Java developers who want to avoid frontend complexity.

  3. JSF (JavaServer Faces) JSF is a strong choice for enterprise systems. You can combine it with PrimeFaces or BootsFaces to get high-quality components. You just need to register the FacesServlet in your Spring configuration.

  4. The Indie Hacker Way (SPA Integration) You can build a React or Vite app and move the build files into the src/main/resources/static folder.

To automate this, use the frontend-maven-plugin. This runs npm install and npm build during your Maven build.

One tip for React users: If you use React Router, create a Controller to redirect unknown paths to index.html. This prevents 404 errors when users refresh the page.

Stop looking for extra servers. Use the power of your embedded Tomcat.

Source: https://dev.to/ganigurgah/spring-boot-is-not-just-a-rest-api-server-50hh