Spring Boot

Complete deployment guide for Spring Boot on NStrim

Overview

Spring Boot is a Java framework that makes it easy to create stand-alone, production-grade applications. It provides auto-configuration, embedded servers, and an opinionated approach to building REST APIs and web applications.

Before You Start
Make sure you have your dashboard open - you'll need the Git credentials displayed there. This template includes Spring Web, Spring Data JPA, MySQL driver, and Thymeleaf templating.

Quick Start

1

Create Repository from Template

On your dashboard, go to the Tools & Deployment tab. Click the "New Repository" button, select the Spring Boot template from the dropdown, enter a repository name and subdomain, then click "Create Repository".

2

Clone Your Repository

git clone https://<git-server>/<username>/<repo-name>.git
cd <repo-name>
3

Configure Database

Update src/main/resources/application.properties with your dashboard credentials:

spring.datasource.url=jdbc:mysql://db.<session-domain>:3306/<username>
spring.datasource.username=<username>
spring.datasource.password=<password>
4

Build and Run

./mvnw spring-boot:run

Server runs on http://localhost:8080 by default.

5

Push Your Changes

git add .
git commit -m "Initial setup"
git push origin main
Every push to Git automatically deploys your application. Check your Module Work URL on the dashboard to see your live site.

Local Development with Docker

If you don't have Java installed locally, you can use Docker to build and run your Spring Boot application.

What is Docker?
Docker creates isolated "containers" with all the software you need (Java, Maven) without installing them on your computer.

Running Commands with Docker

# Build the project
docker run --rm -v $(pwd):/app -w /app maven:3-eclipse-temurin-21 ./mvnw clean package -DskipTests

# Run the application
docker run --rm -v $(pwd):/app -w /app -p 8080:8080 eclipse-temurin:21 java -jar target/*.jar

Database Configuration

The NStrim platform provides you with a MySQL/MariaDB database. Configure your application.properties file with the correct credentials.

Full Configuration

spring.datasource.url=jdbc:mysql://db.<session-domain>:3306/<username>
spring.datasource.username=<username>
spring.datasource.password=<password>
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
Important
Your database name and username are typically the same as your dashboard username (e.g., student01). Check your dashboard credentials section for exact values.

Project Structure

├── src/
│   └── main/
│       ├── java/com/example/
│       │   ├── Application.java          # Spring Boot entry point
│       │   ├── controllers/              # REST controllers
│       │   ├── models/                   # JPA entities
│       │   ├── repositories/             # Spring Data repositories
│       │   └── services/                 # Business logic
│       └── resources/
│           ├── application.properties    # Configuration
│           ├── templates/                # Thymeleaf templates
│           └── static/                   # CSS, JS, images
├── pom.xml                               # Maven dependencies
└── Dockerfile                            # Docker config
        

Common Tasks

Creating a REST Controller

@RestController
@RequestMapping("/api/users")
public class UserController {

    @GetMapping
    public List<User> getAll() {
        return userRepository.findAll();
    }

    @PostMapping
    public User create(@RequestBody User user) {
        return userRepository.save(user);
    }
}

Creating a JPA Entity

@Entity
@Table(name = "users")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;
    private String email;

    // getters and setters
}

Creating a Repository

public interface UserRepository extends JpaRepository<User, Long> {
    Optional<User> findByEmail(String email);
}

Useful Commands

./mvnw spring-boot:run Start development server
./mvnw clean package Build the project
./mvnw test Run tests
./mvnw dependency:tree Show dependency tree

Troubleshooting

Communications link failure / Connection refused

Cause: Database host is incorrect or not accessible.

Solution: Check that spring.datasource.url matches the database host from your dashboard.

Access denied for user

Cause: Wrong username or password.

Solution: Double-check spring.datasource.username and spring.datasource.password match your dashboard credentials exactly.

Port 8080 already in use

Solution: Add server.port=8081 to application.properties or stop the other process.

Whitelabel Error Page (404)

Cause: No controller mapped to the requested URL.

Solution: Ensure your controller has the correct @RequestMapping annotation and the application is scanning the right packages.

Deployment Workflow

Code Change git push mvn package Live!
For more information, visit the official Spring Boot Documentation.