This repository contains two main projects demonstrating Java and React integration: a Spring Boot backend and a React frontend.
A Spring Boot application with REST endpoints, security configuration, and a message repository.
- Location:
jar/ - Main Class:
com.jar.jar.JarApplication - Features:
- REST API with HelloController
- User authentication and security (JWT)
- Message model and repository (JPA)
A React application that interacts with the Java backend via REST API.
- Location:
my-react-app/ - Features:
- React components
- API service using Axios for backend communication
- Java: JDK 21 (or compatible version)
- Maven: 3.6+ (or use included
mvnwwrapper) - Database: H2 (in-memory by default), or MongoDB/SQLite for alternatives
- Node.js: 16+ (includes npm)
- npm: 7+ (comes with Node.js)
-
Install Java and Maven:
- Download and install JDK 21 from Adoptium or Oracle.
- Maven can be installed from maven.apache.org, or use the included
mvnwscript.
-
Navigate to the backend directory:
cd jar -
Build the application (optional, as Spring Boot handles it):
./mvnw clean install
-
Install Node.js and npm:
- Download from nodejs.org.
-
Navigate to the frontend directory:
cd my-react-app -
Install dependencies:
npm install
- Ensure you're in the
jardirectory. - Run the application:
./mvnw spring-boot:run
- The app will start on
http://localhost:8080. - H2 console available at
http://localhost:8080/h2-console(login with JDBC URL:jdbc:h2:mem:testdb, username:sa, password: empty).
- The app will start on
- Ensure you're in the
my-react-appdirectory. - Start the development server:
npm start
- The app will open at
http://localhost:3000.
- The app will open at
The application uses H2 in-memory database by default. No additional setup required. Data is lost on restart.
-
Add SQLite dependency to
pom.xml:<dependency> <groupId>org.xerial</groupId> <artifactId>sqlite-jdbc</artifactId> <version>3.42.0.0</version> </dependency>
-
Update
application.properties:spring.datasource.url=jdbc:sqlite:database.db spring.datasource.driverClassName=org.sqlite.JDBC spring.jpa.database-platform=org.hibernate.community.dialect.SQLiteDialect spring.h2.console.enabled=false
-
Create the database file (optional, JPA will create it).
-
Add MongoDB dependency to
pom.xml:<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency>
Remove H2 dependency if not needed.
-
Update
application.properties:spring.data.mongodb.uri=mongodb://localhost:27017/yourdb # For cloud MongoDB Atlas, use: # spring.data.mongodb.uri=mongodb+srv://username:password@cluster.mongodb.net/yourdb
-
For local MongoDB:
- Install MongoDB from mongodb.com.
- Start MongoDB service.
-
For cloud MongoDB:
- Sign up at MongoDB Atlas.
- Create a cluster and get the connection string.
Note: Switching to MongoDB requires changing the repository from JPA to MongoRepository if using document-based storage.
GET /api/hello- Hello endpoint- Other endpoints as defined in controllers.
Feel free to contribute to either project. Ensure both frontend and backend are tested locally before submitting PRs.