Basic Spring Boot Application Example:

We have already went through various examples using spring, To understand spring please refer here.

What is Spring Boot?
Spring Boot is a way to create stand-alone applications with less or no configurations and has defaults for annotation configuration which we will use in our application

Advantages of Spring Boot:

  • Reduces development time
  • Embedded Servers
  • No XML configuration
  • Integration with Spring JDBC, Spring ORM etc.

Now let us see an basic example to create spring boot application in Netbeans.

Structure:

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>javainfinite.springboot</groupId>
    <artifactId>SpringBootApplication</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    
    <parent>  
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-parent</artifactId>  
        <version>1.5.6.RELEASE</version>     
    </parent> 
    
    <dependencies>  
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-web</artifactId>  
        </dependency>  
    </dependencies>
    
    <build>
     <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
    </build>
    <name>SpringBootApplication</name>
</project>

SpringBootApp.java

package javainfinite.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;



/**
 *
 * @author Vikram
 */
@SpringBootApplication
public class SpringBootApp {
    public static void main(String args[]){
         SpringApplication.run(SpringBootApp.class, args);  
    }
    
}

Output:

We have created basic spring boot application!

 

 

By Sri

Leave a Reply

Your email address will not be published. Required fields are marked *