Загрузка...

Spring boot application Setup. #springboot #java

🌱 Spring Boot Application Setup — Full Step-by-Step Description
0:00 – Spring Boot Initializr
1:44 – Import Project into IntelliJ IDEA
3:04 – Build the Project Using Maven
3:52 – Run the Demo Application
4:12 – What is @SpringBootApplication?
5:42 – Create a Simple DemoController
This guide walks you through setting up a basic Spring Boot application using Spring Initializr and IntelliJ IDEA, building it with Maven, and running a simple REST controller.
0:00 – Spring Boot Initializr

We start by generating a new Spring Boot project using Spring Initializr.

Select Maven as the build tool and Java as the language.

Set the Group as com.example and Artifact as demo.

Add Spring Web as the dependency.

Click Generate to download the project ZIP file.

Extract the ZIP file to your preferred workspace.

1:44 – Import Project into IntelliJ IDEA

Next, we import the project into IntelliJ IDEA:

Open IntelliJ IDEA and click Open or Import Project.

Navigate to the extracted demo folder and select it.

IntelliJ automatically recognizes it as a Maven project and starts indexing.

Wait until indexing is complete to proceed.

3:04 – Build the Project Using Maven

Use the built-in terminal or Maven tool window to compile the project:

./mvnw clean install

This downloads dependencies, compiles the code, and packages it into a JAR.

You should see a “BUILD SUCCESS” message when it's done.

3:52 – Run the Demo Application

Open the DemoApplication.java file — the entry point of the Spring Boot app.

Click the Run icon in the gutter or use the shortcut:

Ctrl + Shift + F10 (Windows/Linux)

Cmd + Shift + F10 (macOS)

You’ll see in the console:

Tomcat started on port 8080

4:12 – What is @SpringBootApplication?

The @SpringBootApplication annotation is a key feature of Spring Boot.
It is a combination of three annotations:

@Configuration: marks the class as a source of bean definitions.

@EnableAutoConfiguration: enables automatic configuration based on dependencies.

@ComponentScan: enables component scanning in the package.
This annotation enables Spring Boot’s magic by auto-configuring everything needed to run the app.

5:42 – Create a Simple DemoController

Let’s create a simple REST controller to test our app:

Create a new class DemoController.java inside com.example.demo.controller

@RestController
@RequestMapping("/api")
public class DemoController {

@GetMapping("/hello")
public String sayHello() {
return "Hello, Spring Boot!";
}
}

This creates a GET endpoint at /api/hello that returns a plain string response.

Visit http://localhost:8080/api/hello in your browser to see the message.

8:00 – Change Server Port to 9090

You can change the default port (8080) to another one like 9090:

Open src/main/resources/application.properties

Add the following line:

server.port=9090

Restart the application.

Now, the app will run on http://localhost:9090, and the endpoint will be accessible at http://localhost:9090/api/hello

Видео Spring boot application Setup. #springboot #java канала Chakri Codes Java
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять