0% found this document useful (0 votes)
8 views3 pages

Java Spring Boot Sample App

This document describes a complete Java Spring Boot sample application that includes a REST API with a welcome message and a greeting endpoint. It outlines the project structure, including key files like pom.xml, DemoApplication.java, HelloController.java, and application.properties. Instructions for running the application using Maven are also provided.

Uploaded by

lagos78703
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Java Spring Boot Sample App

This document describes a complete Java Spring Boot sample application that includes a REST API with a welcome message and a greeting endpoint. It outlines the project structure, including key files like pom.xml, DemoApplication.java, HelloController.java, and application.properties. Instructions for running the application using Maven are also provided.

Uploaded by

lagos78703
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Spring Boot sample app

Here's a complete Java Spring Boot sample app.

✅ App Overview
A simple Spring Boot REST API that:
Returns a welcome message at /
Has a REST endpoint at /api/hello
Uses standard Maven structure

📁 Project Structure
1 sample-springboot-app/
2 ├── src/
3 │ └── main/
4 │ ├── java/
5 │ │ └── com/
6 │ │ └── example/
7 │ │ └── demo/
8 │ │ ├── [Link]
9 │ │ └── [Link]
10 │ └── resources/
11 │ └── [Link]
12 ├── [Link]
13

1. [Link]
1 <project xmlns="[Link]
2 xmlns:xsi="[Link]
3 xsi:schemaLocation="[Link]
4 [Link]
5
6 <modelVersion>4.0.0</modelVersion>
7 <groupId>[Link]</groupId>
8 <artifactId>sample-springboot-app</artifactId>
9 <version>1.0.0</version>
10 <packaging>jar</packaging>
11
12 <name>Sample Spring Boot App</name>
13
14 <parent>
15 <groupId>[Link]</groupId>
16 <artifactId>spring-boot-starter-parent</artifactId>
17 <version>3.2.5</version>
18 <relativePath/> <!-- lookup parent from repository -->
19 </parent>
20
21 <dependencies>
22 <!-- Spring Boot Starter Web -->
23 <dependency>
24 <groupId>[Link]</groupId>
25 <artifactId>spring-boot-starter-web</artifactId>
26 </dependency>
27
28 <!-- Testing -->
29 <dependency>
30 <groupId>[Link]</groupId>
31 <artifactId>spring-boot-starter-test</artifactId>
32 <scope>test</scope>
33 </dependency>
34 </dependencies>
35
36 <build>
37 <plugins>
38 <!-- Spring Boot Maven Plugin -->
39 <plugin>
40 <groupId>[Link]</groupId>
41 <artifactId>spring-boot-maven-plugin</artifactId>
42 </plugin>
43 </plugins>
44 </build>
45 </project>
46

2. [Link]
Path: src/main/java/com/example/demo/[Link]

1 package [Link];
2
3 import [Link];
4 import [Link];
5
6 @SpringBootApplication
7 public class DemoApplication {
8 public static void main(String[] args) {
9 [Link]([Link], args);
10 }
11 }
12

3. [Link]
Path: src/main/java/com/example/demo/[Link]

1 package [Link];
2
3 import [Link];
4 import [Link];
5
6 @RestController
7 public class HelloController {
8
9 @GetMapping("/")
10 public String home() {
11 return "Welcome to the Sample Spring Boot App!";
12 }
13
14 @GetMapping("/api/hello")
15 public String helloApi() {
16 return "Hello from Spring Boot API!";
17 }
18 }
19

4. [Link]
Path: src/main/resources/[Link]

1 # Use default settings (can be empty)


2 [Link]=8080
3

🚀 How to Run
With Maven:
1 mvn spring-boot:run
2

Or, package it:

1 mvn clean package


2 java -jar target/[Link]
3

Then open [Link] and [Link]

You might also like