Home Java Create spring boot application in IntelliJ idea

Create spring boot application in IntelliJ idea

by Vermadeals
Creating-a-spring-boot-project-Vermadeals

First, you need to IntelliJ IDEA for development then click and download IntelliJ IDEA.

  1. Click create new project button:
Click create new project button
Click create new project button

2.  Create the Maven project:

Create the Maven  project
Create the Maven project

3. Enter your project name:

Enter your project name
Enter your project name

4. Add the following dependency in the pom.xml file:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>2.3.4.RELEASE</version>
    </dependency>
</dependencies>

5. POM.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>org.example</groupId>
    <artifactId>Spring_Boot_Rest_APIs</artifactId>
    <version>1.0-SNAPSHOT</version>
 
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
 
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.3.4.RELEASE</version>
        </dependency>
    </dependencies>
</project>

6. Create one main class Application.java:

package com;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.web.WebApplicationInitializer;
 
@SpringBootApplication
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {
    public static void main(String[] arg){
        SpringApplication.run(Application.class,arg);
    }
}

7. Create one testing Controller class PingController.java:

package com.controller;
 
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
public class PingController {
 
    @RequestMapping(value = "/Hello", method = RequestMethod.GET)
    public String ping(){
        return "Subscribe Technical Ramchander Youtube Channel";
    }
}

8. Now Run your application.java application-

First right-click in your application class and then click to run button

After running your application:

localhost

Go to Brower and run this URL –

 http://localhost:8080/Hello

Jai Hind Vande Mataram

You may also like