Hello friends today I am going to discuss one of the latest innovation by the Spring Team (Pivotal Team) is Spring Boot, oops… sorry..friends yes I know I am late for this discussion right now but it is not too late for spring boot because this is actual time for major adoption of Spring Boot for scratch project in the spring framework 🙂
. If you are already familiar with spring framework then it is too easy to learn because Spring Boot is nothing but it developed on top of existing Spring Framework
. It uses completely new development model to make Java Development very easy by avoiding some tedious development steps and boilerplate code and configuration.
Table of Contents
Hello World example using spring boot
Servlet containers support
Template Engines Support
Spring Boot & Spring MVC
Spring boot tutorials
- Introducing to Spring Boot
- What is Spring Boot?
- Spring Boot Primary Goals
- Why New Project Need Spring Boot?
- What Spring Boot isn’t
- Pros/Cons of Spring Boot
- Spring boot releases
- Getting started with Spring
1. Introducing to Spring Boot
Spring Team has released one of major innovation on the top of existing Spring Framework is Spring Boot. It is a completely new project from Pivotal Team (The Spring Team). Spring Boot is their latest innovation to keep up to date with the changing technology needs. The primary motivation behind developing Spring Boot is to simplify the process for configuring and deploying the spring applications.
Spring Boot offers a new paradigm for developing Spring applications with minimal friction. With Spring Boot, you’ll be able to develop Spring applications with more agility and be able to focus on addressing your application’s functionality needs with minimal (or possibly no) thought of configuring Spring itself. It uses completely new development model to make Java Development very easy by avoiding some tedious development steps and boilerplate code and configuration.
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. We take an opinionated view of the spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
You can use Spring Boot to create Java applications that can be started using java -jar or more traditional war deployments. We also provide a command line tool that runs “spring scripts”.
2. What is spring boot?
First of all Spring Boot is not a framework, it is a way to ease to create stand-alone application with minimal or zero configurations. It is approach to develop spring based application with very less configuration. It provides defaults for code and annotation configuration to quick start new spring projects within no time. It leverages existing spring projects as well as Third party projects to develop production ready applications. It provides a set of Starter Pom’s or gradle build files which one can use to add required dependencies and also facilitate auto configuration.
Spring Boot automatically configures required classes depending on the libraries on its classpath. Suppose your application want to interact with DB, if there are Spring Data libraries on class path then it automatically sets up connection to DB along with the Data Source class.
3. Spring Boot Primary Goals
Spring Boot primary goals are:
- Provide a radically faster and widely accessible getting started experience for all Spring development.
- Be opinionated out of the box, but get out of the way quickly as requirements start to diverge from the defaults.
- Provide a range of non-functional features that are common to large classes of projects (e.g. embedded servers, security, metrics, health checks, externalized configuration).
- Absolutely no code generation and no requirement for XML configuration, to avoid XML Configuration completely
- To avoid defining more Annotation Configuration(It combined some existing Spring Framework Annotations to a simple and single Annotation)
- To avoid writing lots of import statements
- To provide some defaults to quick start new projects within no time.
4. Why New Project Need Spring Boot?
Suppose we are developing one of Hello World application in Spring Framework, for that there is only one item is specific to developing the Hello World functionality: the controller. The rest of it is generic boilerplate that you’d need for any web application developed with Spring. But if all Spring web applications need it, why should you have to provide it? So there are following things any new project need Spring Boot.
- To ease the Java-based applications Development, Unit Test and Integration Test Process.
- To reduce Development, Unit Test and Integration Test time by providing some defaults.
- To increase Productivity.
- When we talk about defaults, Spring Boot has its own opinions. If you are not specifying the details, it will use its own default configurations. If you want persistence, but don’t specify anything else in your POM file, then Spring Boot configures Hibernate as a JPA provider with an HSQLDB database.
- To provide bunch of non-functional features/solutions that are very much common to large scale projects (e.g. embedded servers, security, metrics, health checks, externalized configuration).
5. What Spring Boot Isn’t?
As above mention Spring Boot is not a framework to write applications, it helps you to develop and build, package and deploy application with minimal configuration or zero configuration.
It is not an application server. But it’s the embedded servlet container that provides application server functionality, not Spring Boot itself.
Similarly, Spring Boot doesn’t implement any enterprise Java specifications such as JPA or JMS. For example, Spring Boot doesn’t implement JPA, but it does support JPA by auto-configuring the appropriate beans for a JPA implementation (such as Hibernate)
Finally, Spring Boot doesn’t employ any form of code generation to accomplish its magic. Instead, it leverages conditional configuration features from Spring 4, along with transitive dependency resolution offered by Maven and Gradle, to automatically configure beans in the Spring application context.
In short, at its heart, Spring Boot is just Spring.
Future Spring projects would not have any XML configurations as part of it, everything will be handled by the project Spring Boot.
6. Pros/Cons of Spring Boot
Pros of Spring Boot:
- It is very easy to develop Spring Based applications with Java or Groovy.
- It reduces lots of development time and increases productivity.
- It avoids writing lots of boilerplate Code, Annotations and XML Configuration.
- It is very easy to integrate Spring Boot Application with its Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data, Spring Security etc.
- It follows “Opinionated Defaults Configuration” Approach to reduce Developer effort
- It provides Embedded HTTP servers like Tomcat, Jetty etc. to develop and test our web applications very easily.
- It provides CLI (Command Line Interface) tool to develop and test Spring Boot (Java or Groovy) Applications from command prompt very easily and quickly.
- It provides lots of plugins to develop and test Spring Boot Applications very easily using Build Tools like Maven and Gradle
- It provides lots of plugins to work with embedded and in-memory Databases very easily.
Limitation of Spring Boot:
It is very tough and time consuming process to convert existing or legacy Spring Framework projects into Spring Boot Applications. It is applicable only for brand new/Greenfield Spring Projects.
7. Spring boot releases
Latest Release: Spring Boot 1.3.3 and 1.4.0 available now. You require minimum Spring Framework 4.2.2 for this version.
- · Executable JAR Layout
- · Startup error improvements
- · Hibernate 5
- · Spring Framework 4.3
- · Third Party Library
- · Custom JSON Serializer and Deserializer
- · New auto-configuration support
- o Couchbase
- o Neo4j
- o Narayana transactional manager
- o Caffeine Cache
- · Actuator improvements
- · Testing improvements
8. Getting started with Spring Boot
Ultimately, a Spring Boot project is just a regular Spring project that happens to leverage Spring Boot starters and auto-configuration. To Start Opinionated Approach to create Spring Boot Applications, The Spring Team (The Pivotal Team) has provided the following three approaches.
We can develop two flavors of Spring-Based Applications using Spring Boot
- Java-Based Applications
- Groovy Applications
We can use Spring Boot CLI or Spring STS IDE or Spring Initializr Website to develop Spring Boot Groovy Applications. However, we can use Spring STS IDE or Spring Initializr Website to develop Spring Boot Java Applications.
Anyhow, Groovy is also JVM language almost similar to Java Language. We can combine both Groovy and Java into one Project. Because like Java files, Groovy files are finally compiled into *.class files only. Both *.groovy and *.java files are converted to *.class file (Same byte code format).
Spring Boot Framework Programming model is inspired by Groovy Programming model. Spring Boot internally uses some Groovy based techniques and tools to provide default imports and configuration.
Spring Boot Framework also combined existing Spring Framework annotations into some simple or single annotations. We will explore those annotations one by one in coming posts with some real-time examples.
Spring Boot Framework drastically changes Spring-Java Based Applications Programming model into new Programming model. As of now, Spring Boot is at initial stage only but future is all about Spring Boot only.
Spring Boot CLI
It is the easiest and quickest way to start using the Spring Boot. It is a command line tool used for executing the groovy scripts. In summary, you can install this tool by following these steps:
1. Download the binary distributions for this project from here
. Spring Boot CLI requires Java JDK v1.6 or above in order to run. Groovy v2.1 is packaged as part of this distribution, and therefore does not need to be installed (any existing Groovy installation is ignored)
2. If you unpack the zip file, you will find spring.bat which will check the all the settings. This script can be found under the directory /bin.
9. Hello World example using spring boot
We can develop two flavors of Spring-Based Applications using Spring Boot.
- Groovy Applications
- Java-Based Applications
Let’s develop a simple “Hello World!” web application. Create the app.groovy with the following lines of code. Here we are going explain same example from Spring Boot documentation.