Spring Boot Web Example
Table of Contents
In this article, I am going to showing how to create a spring boot web example project.
Pre-Requisites
- Java 1.8
- Spring Boot 2.2.5.RELEASE
- Eclipse IDE
Spring boot project can be created in multiple ways.
- Eclipse Maven
- STS
- start.spring.io
Here I am going to show start.spring.io using to create spring boot project.
Step 1:
Open any browser in your system and type https://start.spring.io/ in the address bar
Step 2:
Project: Maven Project
Language: Java
Spring Boot: 2.2.5
Project Metadata :`
Group: com.narayanatutorial
Artifact: SpringBootWebExample
Click on Options, Select War in Packaging
Dependencies: nothing select because by default spring started included.
Step 3:
Unzip the downloaded project in your system and then import it into eclipse as maven project.
Open Eclipse, go to File -> Import -> Maven -> Existing Maven Projects –> click on Next — > browse the unzipped folder and then click on finish.
Step 4:
The project was imported successfully and then execute the main java program.
Source Code Details
SpringBootWebExampleApplication.java
package com.narayanatutorial.SpringBootWebExample; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringBootWebExampleApplication { public static void main(String[] args) { SpringApplication.run(SpringBootWebExampleApplication.class, args); } }
pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.narayanatutorial</groupId>
<artifactId>SpringBootWebExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringBootWebExample</name>
<description>Demo project for Spring Boot</description>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Get full source code from git.
Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in the IT industry for more than 12 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting, Website Development, and IAM(ForgeRock) Specialist
I am a self-learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.