

So, in React Project, let’s open index.js file and change BrowserRouter into HashRouter. It will keep the UI route in hash part of the URL, which should not make the server return 404. To handle this error, we’re gonna enable hash(#) in React App Routing by using HashRouter. Spring Boot + React: Whitelabel Error Page Serve React App on Spring Bootīuild and run the Spring Boot server with commands: In the code above, we specify outputDirectory for the destination folder, and resource>directory for the source folder. Now we need to copy all files from React build folder to src/ target/ classes/ static folder of Spring Boot project.

Integrate React production into Spring Boot Project Now you can see new build folder with content as following: The build folder is ready to be deployed. You can control this with the homepage field in your package.json. The project was built assuming it is hosted at /.

Please run the following command: `yarn upgrade`ĥ2.63 KB build\static\js\2.Ģ2.44 KB build\static\css\2.Ģ.38 KB build\static\js\ħ74 B build\static\js\ġ44 B build\static\css\ > build D:\Projects\ReactProjects\react-crudĬreating an optimized production build.īrowserslist: caniuse-lite is outdated. The first thing we need to do is to build React App for production. Integrate React.js with Spring Boot Build React AppĬurrently React Client and Express server work independently on ports 80. Let’s continue to the most important part. Now we have 2 projects together in Spring Tool Suite: The instruction can be found in the post: Spring Boot, Spring Data JPA – Rest CRUD API example Then open pom.xml and add these dependencies: Use Spring web tool or your development tool ( Spring Tool Suite, Eclipse, Intellij) to create a Spring Boot project. You can use your own Spring Boot Project, or just download the source code on Github, or follow these steps to create a new one. Press OK, then Apply, the result will be like this: Press Add Filter…, choose Filter Type: Exclude all, Applies to: Files and folders, and check All children (recursive), with ‘File and Folder Atributes’, we specify node_modules:.Right click on react-crud project, choose Properties, then Resource -> Resource Filter.To clean the source code in STS, we need to remove node_modules folder by following the steps: Open Spring Tool Suite, right click on Package Explorer and choose Import -> General -> Projects from Folder or Archieve, press Next.įind the React Project that we’ve just created above and press Finish, react-crud is imported like this: Because I want to keep this tutorial simple and brief, please continue to develop this App with instruction in the post: React.js CRUD example to consume Web API Import React Project to Spring Tool Suite
