Reputation: 373
I can't figure out how to install React.js for Spring framework.
A website said to first install NPM. Yes, I did that.
But how can I use React.js in Spring MVC?
I'm a beginning developer.
Upvotes: 1
Views: 4944
Reputation: 12051
Spring MVC
and ReactJS
follow some different concepts of designing your webapplication. With Spring MVC your create most of the time server side rendered webapps with JSP
s or you use a template engine like Thymeleaf
.
With ReactJS
you are building a Singe Page Application (SPA) which can be accessed with a SINGLE HTML file, often index.html
and your JavaScript is doing the rendering. With Spring MVC
you provide several .html
files and use Spring to route the different routes to your different .html
files and render them on the server side.
The only thing I can guess is to serve your finally built ReactJS
which consists only of one .html
and several .js
and other assets with a Spring MVC application which acts like a simple Webserver.
Furthermore you can use Spring MVC to provide RESTful interfaces for your React application.
Upvotes: 0
Reputation: 2320
The best answer I can give you is to walk through this tutorial, step by step.
https://spring.io/blog/2015/09/01/react-js-and-spring-data-rest-part-1-basic-features
To answer your first question, no, you do not need to use node.js tools to use React with Spring MVC. The tutorial above says:
This tutorial won’t go into extensive detail on how it uses require.js to load JavaScript modules. But thanks to the frontend-maven-plugin, you don’t have to install any of the node.js tools to build and run the code.
Upvotes: 1