Skip to content

Latest commit

 

History

History
180 lines (125 loc) · 4.27 KB

File metadata and controls

180 lines (125 loc) · 4.27 KB

Java Spring Boot MongoDB Sample MFlix Application

This is a full-stack movie browsing application built with Java Spring Boot and Next.js, demonstrating MongoDB operations using the sample_mflix dataset. The application showcases CRUD operations, aggregations, and MongoDB Search using Spring Data MongoDB.

Project Structure

├── README-JAVA-SPRING.md
├── client/                 # Next.js frontend (TypeScript)
└── server/java-spring/     # Java Spring Boot backend
    ├── src/
    ├── pom.xml
    ├── .env.example
    └── mvnw

Prerequisites

  • Java 21 or higher
  • Node.js 20 or higher
  • MongoDB Atlas cluster or local deployment with the sample_mflix dataset loaded
  • Maven (included via Maven Wrapper)

Getting Started

1. Configure the Backend

Navigate to the Java Spring server directory:

cd server/java-spring

Create a .env file from the example:

cp .env.example .env

Edit the .env file and set your MongoDB connection string:

# MongoDB Connection
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/?retryWrites=true&w=majority

# Server Configuration
PORT=3001

# CORS Configuration
CORS_ORIGIN=http://localhost:3000

Note: Replace username, password, and cluster with your actual MongoDB Atlas credentials.

2. Start the Backend Server

From the server/java-spring directory, run:

# Using Maven Wrapper (recommended)
./mvnw spring-boot:run

# Or on Windows
mvnw.cmd spring-boot:run

The server will start on http://localhost:3001. You can verify it's running by visiting:

3. Configure and Start the Frontend

Open a new terminal and navigate to the client directory:

cd client

Install dependencies:

npm install

Start the development server:

npm run dev

The Next.js application will start on http://localhost:3000.

4. Access the Application

Open your browser and navigate to:

Features

  • Browse Movies: View a paginated list of movies from the sample_mflix dataset
  • Search: Full-text search using MongoDB Search
  • Filter: Filter movies by genre, year, rating, and more
  • Movie Details: View detailed information about each movie
  • Aggregations: Complex data aggregations and analytics

Development

Backend Development

The Java Spring Boot backend uses:

  • Spring Data MongoDB for database operations
  • Spring Boot Web for REST API
  • SpringDoc OpenAPI for API documentation
  • Maven for dependency management

To run tests:

cd server/java-spring
./mvnw test

Frontend Development

The Next.js frontend uses:

  • React 19 with TypeScript
  • Next.js 16 with App Router
  • Turbopack for fast development builds

Development Mode

For active development with hot reloading and fast refresh:

cd client
npm run dev

This starts the development server on http://localhost:3000 with Turbopack for fast rebuilds.

Production Build

To create an optimized production build and run it:

cd client
npm run build  # Creates optimized production build
npm start      # Starts production server

The production build:

  • Minifies and optimizes JavaScript and CSS
  • Optimizes images and assets
  • Generates static pages where possible
  • Provides better performance for end users

Linting

To check code quality:

cd client
npm run lint

Issues

If you have problems running the sample app, please check the following:

  • Verify that you have set your MongoDB connection string in the .env file.
  • Verify that you have started the Java Spring server.
  • Verify that you have started the Next.js client.
  • Verify that you have no firewalls blocking access to the server or client ports.

If you have verified the above and still have issues, please open an issue on the source repository mongodb/docs-sample-apps.