Loading
 
What's Next: View All Tutorial →

Spring Boot Hello World - Project set up

Why Springboot? Spring boot makes it easy to create stand-alone, production-grade Spring based Application that you can "just run", create spring based application https://start.spri...

Published Date: 05/09/2018  Last Modified Date: 05/09/2018    New Post



Why Springboot?


Spring boot makes it easy to create stand-alone, production-grade Spring based Application that you can "just run", create spring based application


https://start.spring.io/  website provide platform to generate the spring boot project.

Spring boot is a maven project having following structure
 

Folder Structure 

src
--main
----java
------com
--------demo
----------spring
------------ Application.java
----resources
------application.properties
------
------static
------templates


The application.properties have all the property value. In Spring boot, most of the functionality we can achieve using property configuration


resource/static  - Static folder holds the static content like images, css , js and html code

Application.java is the start of the SpringbootApplication having @SpringbootApplication anotation.
 

Maven Dependency


<?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>com.demo</groupId>
	<artifactId>spring-boot-demo</artifactId>
	<version>1.0</version>
	<packaging>jar</packaging>

	<name>spring-boot-demo1</name>
	<description>Demo project for Spring Boot</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.4.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>


</project>

Application.Java

 
package com.demo.spring;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
	private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);

		LOGGER.info("Application Started");

	}
}
 

Output:

 

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.4.RELEASE)

05-09-2018 09:58:34.155 [main] INFO  com.demo.spring.Application.logStarting - Starting Application on e24-PC with PID 2500 (C:\work\spring-boot-demo\target\classes started by e24 in C:\work\spring-boot-demo)
05-09-2018 09:58:34.160 [main] INFO  com.demo.spring.Application.logStartupProfileInfo - No active profile set, falling back to default profiles: default
05-09-2018 09:58:34.194 [main] INFO  org.springframework.context.annotation.AnnotationConfigApplicationContext.prepareRefresh - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@3b07a0d6: startup date [Wed Sep 05 09:58:34 IST 2018]; root of context hierarchy
05-09-2018 09:58:34.884 [main] INFO  org.springframework.jmx.export.annotation.AnnotationMBeanExporter.afterSingletonsInstantiated - Registering beans for JMX exposure on startup
05-09-2018 09:58:34.899 [main] INFO  com.demo.spring.Application.logStarted - Started Application in 1.064 seconds (JVM running for 1.665)
05-09-2018 09:58:34.901 [main] INFO  com.demo.spring.Application.main - Application Started
05-09-2018 09:58:34.903 [Thread-3] INFO  org.springframework.context.annotation.AnnotationConfigApplicationContext.doClose - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@3b07a0d6: startup date [Wed Sep 05 09:58:34 IST 2018]; root of context hierarchy
05-09-2018 09:58:34.905 [Thread-3] INFO  org.springframework.jmx.export.annotation.AnnotationMBeanExporter.destroy - Unregistering JMX-exposed beans on shutdown
Awaiting for Administrator approval




← Back to list


Related Post




×