Search code examples
reactjsspring-boottomcatnext.jsreact-fullstack

How do I serve the NextJs application from spring boot application?


I have a spring boot rest API service that is running in tomcat.

I have a NextJS UI app running on the node js server.

Now I want my NextJs app to be served by the tomcat server.

What are the necessary steps I need to do for my nextjs app to be served by spring boot static folder?


Solution

  • I found the answer.

    Step -1 : Edit package.json -> add "export":" next export" in the scripts property

    Step - 2: The above step will build a folder named "out". Copy the contents of out folder. Paste it in the src -> main -> resources -> static folder.

    Step -3: Now build the spring boot jar/war, then run it. It will serve the contents inside the static folder.