1

I am developing Spring boot application with react client using gradle. I am new to all these technologies. Currently I am able to create war file which includes following folders:

  • META-INF
  • public (contains build of client part - index.html, index.js and other .js scripts)
  • WEB-INF (contains compiled spring boot backend app)

Currently, after deploying war to tomcat, I am able to access client static content on http://localhost:8080/app-name/public/. Also I am able to access routes defined in spring controllers on http:// localhost:8080/app-name/route (these are just for testing purposes, I want this commands to be accessed only through REST calls from client).

Now, what I want is make that static client content available under route http://localhost:8080/app-name/xxx-yyy/public

I don't know what is right way to do this (actually, only way I know is create xxx-yyy subfolder on tomcat a put public folder inside it. I think this is bad approach). Other way would be somehow forward from spring controller but I am not able to do that.

It is possible that this is bad concept and I should make it other way. I would be glad for any suggestion.

Thank you

7
  • Are you using Spring Boot? Because with Spring Boot the Tomcat server is embedded into a JAR file, so, you won't be working with WARs. Commented Jun 10, 2017 at 10:46
  • basically you want to bind your controller actions with reactjs? Commented Jun 10, 2017 at 11:09
  • @lbpeppers I am not using the embedded Tomcat server. My company wants deploy it on their own tomcat in docker. So I have to work with WAR. Commented Jun 10, 2017 at 11:28
  • @VikramSaini Yes, if it is possible with my current structure of WAR file (or suggestion what should in it) Commented Jun 10, 2017 at 11:29
  • i can help you with JAR and not with WAR.why are you working with WAR's? Commented Jun 10, 2017 at 12:47

1 Answer 1

2

I guess you are using create-react-app.

For production deployment, the React application consists of static files only. These files are generated with create-react-app : npm run build. Cf. the official docs about deployment.

So you just have to serve these static files in your Spring Boot app, for instance in the folder src/main/resources/static. Here is the documentation about static content in Spring Boot.

At the end, Tomcat will run dynamic REST web services (for instance at /api) and React files.

Note: if you are using Spring Security, make sure that React files such as index.html are publicly available.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.