Key components and internals of Spring Boot framework--turn

Source: Internet
Author: User
Tags spring initializr spring boot actuator groovy script

Original address: Http://www.journaldev.com/7989/key-components-and-internals-of-spring-boot-framework

In my previous post ' Introduction to spring Boot ', we have the discussed about Spring boot basics. Now we'll discuss about ' what is the main components of Spring boot ' and ' How Spring Boot works under-the-hood '.

Key components of the Spring Boot Framework

Spring Boot Framework has mainly four major components.

    • Spring Boot Starters
    • Spring Boot Autoconfigurator
    • Spring Boot CLI
    • Spring Boot Actuator

note:-
In addition to these four major, there is, and more Spring Boot components:

    • Spring INITILIZR
    • Spring Boot IDEs

To Quick start new spring Boot projects, we can use the "Spring initializr" Web interface. Spring Initializr Url:http://start.spring.io.

We have many spring Boot IDEs like the Eclipse IDE, IntelliJ idea, Spring STS Suite etc. We'll discuss these in coming posts.

Now we'll discuss these Spring Boot four, one by one in detail.

Spring Boot Starter

Spring Boot Starters is one of the major keys features or components of the Spring boot Framework. The main responsibility of Spring Boot Starter is to combine a group of common or related dependencies into single Depende Ncies. We'll explore this statement in detail with one example.

For instance, we would like to develop a Spring webapplication with Tomcat WebServer. Then we need to add the following minimal jar dependencies in your Maven ' s pom.xml file or Gradle ' s Build.gradle file

    • Spring core Jar file (Spring-core-xx.jar)
    • Spring Web Jar file (Spring-web-xx.jar)
    • Spring Web MVC Jar file (Spring-webmvc-xx.jar)
    • Servlet Jar file (Servlet-xx.jar)

If we want to add some database stuff and then we need to add database related jars like spring JDBC jar file, Spring ORM jar files,spring Transaction Jar file etc.

    • Spring JDBC Jar file (Spring-jdbc-xx.jar)
    • Spring ORM Jar file (Spring-orm-xx.jar)
    • Spring Transaction Jar file (Spring-transaction-xx.jar)

We need to define lot of dependencies in our build files. It is very tedious and cumbersome the tasks for a Developer. And also it increases our build file size.

What's the solution to avoid this much dependencies definitions in our build files? The solution is Spring Boot Starter component.

Spring Boot Starter component combines all related jars to single jar file So, we can add only jar file dependency t o Our build files. Instead of adding above 4 jars files to our build file, we need to add one and only one jar file: "Spring-boot-starter-web "Jar file.

When we add the "Spring-boot-starter-web" jar file dependency to our build file, then spring boot Framework would automatically Download all required jars and add to our project classpath.

In the same, "spring-boot-starter-logging" JAR file loads all it's dependency jars like "jcl-over-slf4j, JUL-TO-SLF4J, LOG4J-OVER-SLF4J, Logback-classic "to our project classpath.

Major Advantages of Spring Boot Starter
    • Spring Boot Starter reduces defining many dependencies simplify project build dependencies.
    • Spring Boot Starter simplifies project build dependencies.

That's it about Spring Boot Starter component. We'll discuss some more details with some Spring Boot examples in coming posts.

Spring Boot Autoconfigurator

Another important key component of Spring boot Framework is spring boot autoconfigurator. Most of the spring IO Platform (Spring Framework) Critics opinion are that ' to develop a spring-based application requires Lot of configuration (either XML configuration of Annotation configuration). Then how to solve this problem.

The solution to this problem is Spring Boot autoconfigurator. The main responsibility of Spring Boot autoconfigurator is to reduce the spring Configuration. If We develop spring applications in spring boot,then we dont need to define single XML configuration and almost no or min iMAL Annotation configuration. Spring Boot Autoconfigurator component would take care of providing those information.

For instance, if we want to declare a spring MVC application using spring IO Platform and then we need to define lot of XML C Onfiguration like views, view resolvers etc. But if we use the Spring Boot Framework, then we dont need to define those XML Configuration. Spring Boot Autoconfigurator would take of this.

If we use "Spring-boot-starter-web" JAR file with our project build file and then spring boot Autoconfigurator'll resolve Vie WS, view resolvers etc. automatically.

And also Spring Boot reduces defining of Annotation configuration. If we use the @SpringBootApplication annotation at class level and then Spring Boot Autoconfigurator'll automatically add all r equired Annotations to Java Class bytecode.

If we go through Spring Boot documentation, we can find the following definition for @SpringBootApplication.

12345678 @Target(value=TYPE)@Retention(value=RUNTIME)@Documented@Inherited@Configuration@EnableAutoConfiguration@ComponentScanpublic@interfaceSpringBootApplication

That is, @SpringBootApplication = @Configuration + @ComponentScan + @EnableAutoConfiration.

That's it about Spring Boot autoconfigurate component. We'll discuss some more details with some Spring Boot examples in coming posts.

note:-

    • In simple words, spring boot Starter reduces build ' s dependencies and spring boot autoconfigurator reduces the spring Conf Iguration.
    • As we discussed that Spring boot Starter have a dependency on spring boot autoconfigurator, spring boot Starter triggers Sp Ring Boot Autoconfigurator automatically.
Spring Boot CLI

Spring boot CLI (Command line Interface) was a spring boot software to run and test Spring boot applications from Command PR Ompt. When we run the Spring boot applications using CLI, then it internally uses spring boot Starter and spring boot Autoconfigurat E Resolve all dependencies and execute the application.

We can run even spring WEB applications with the simple spring Boot CLI Commands.

Spring Boot CLI has introduced a new "Spring" command to execute Groovy Scripts from command prompt.

Spring Command Example:

1 spring run HelloWorld.groovy

Here Helloworld.groovy is a groovy script FileName. Like Java source file names has *.java extension, Groovy script files has *.groovy extension. "Spring" command executes Helloworld.groovy and produces output.

Spring Boot CLI component requires many steps like CLI installation, CLI Setup, Develop simple Spring boot application and Test it. So we is going to dedicate another post to discuss it in details with some Spring Boot Examples. Refer my next post on Spring Boot CLI.

Spring Boot Actuator

Spring Boot Actuator Components gives many features, but both major features are

    • Providing Management endpoints to Spring Boot applications.
    • Spring Boot Applications Metrics.

When we run our Spring boot WEB application using CLI, Spring boot actuator automatically provides hostname as "localhost" and default port number as "8080". We can access this application using the "http://localhost:8080/" end point.

We actually use the HTTP Request methods like GET and POST to represent Management endpoints using Spring Boot actuator.

We'll discuss some more details on Spring Boot actuator in coming posts.

Internals of Spring Boot Framework

It's always recommended to understand how Spring Boot Framework reduces build ' s dependencies,spring Configuration, etc. How Spring Boot works under-the-hood.

If you is familiar with Groovy programming language and then you know most of the stuff. In groovy, we don ' t need to add some some imports and no need to add some dependencies to Groovy project. When we compile groovy scripts using groovy Compiler (GROOVYC), it'll automatically adds all default import statements th En compile it.

In the same, Groovy programming language contains a jar Dependency Resolver to resolve and add all required JAR files To Groovy Project classpath.

Spring Boot Framework internally uses Groovy to add some defaults like Default import statements, application main () Metho D etc. When we run Groovy Scripts from CLI Command prompt, it uses this main () method to run the Spring Boot application.

Grape

Grape is an Embedded Dependency Resolution engine. Grape is a JAR Dependency Manager embedded into Groovy. Grape lets us quickly add Maven repository dependencies to our project Classpath to reduce build file definitions.

Spring Boot Framework programming model is mainly inspired by Groovy programming model. Spring Boot Framework Internally depends on these, major Components:groovy and Grape.

You can refer Grape documentation http://docs.groovy-lang.org/latest/html/documentation/grape.html for more details.

That's it about Spring components and internals. We'll discuss about these the details with the some Spring Boot examples in coming posts.

Key components and internals of Spring Boot framework--turn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.