Spring boot quickly builds spring framework

Source: Internet
Author: User
Tags tomcat server

Spring is an open source framework, and spring is a lightweight Java development framework that emerged in 2003 by Rod Johnson in his book expert one-on-one development and Some of the concepts and prototypes elaborated in design are derived. It is created to address the complexities of enterprise application development. One of the main advantages of the framework is its layered architecture, which allows the user to choose which component to use, while providing an integrated framework for Java EE application development. Spring uses basic JavaBean to accomplish things that were previously only possible by EJBS. However, the use of spring is not limited to server-side development. From the standpoint of simplicity, testability, and loose coupling, any Java application can benefit from spring. The core of spring is control inversion (IoC) and facet-oriented (AOP). In short, spring is a layered, javase/eefull-stack (one-stop) lightweight, open-source framework.


Spring Boot is a new subproject of the spring framework that is used to create a Spring 4.0 project. Its development began in the 2013. April 2014 released 1.0.0 version. It automatically configures the various components of Spring and does not rely on code generation and XML configuration files. Spring Boot also provides recommended component configurations for common scenarios. Spring Boot can greatly improve development efficiency when using the spring framework. Spring Boot is described in more detail in this article.


Spring Boot contains the following features:

1. Create a Spring application that can run independently.

2, directly embedded Tomcat or Jetty server, do not need to deploy WAR files.

3. Provide the recommended base POM file to simplify the Apache Maven configuration.

4, as far as possible according to project dependencies to automatically configure the Spring framework.

5. Provide functions that can be used directly in the production environment, such as performance indicators, application information, and application health checks.

6, no code generation, and no XML configuration file.


Create a new MAVEN feature and copy the following code directly into 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>com.example</groupid><artifactid>springbootsimple</artifactid ><version>1.0-snapshot</version><properties> <spring.boot.version>1.1.4. release</spring.boot.version></properties><dependencies> <dependency> < groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</ artifactid> <version>${spring.boot.version}</version> </dependency></ Dependencies><build> <plugins> <plugin> <groupid> Org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid><version>${spring.boot.version}</version> <executions > <execution> <goals> <goal>repackage</goal> </goals>  </execution> </executions> </plugin> </plugins></build>< /project>

From the Pom.xml file above, you can see that the application claims very few dependencies, only one "Org.springframework.boot:spring-boot-starter-web", and not a lot of dependencies like other spring projects need to be declared. When you use the Maven command "MVN dependency:tree" to see the actual dependencies of a project, you will find that it contains dependencies such as the Spring MVC framework, SLF4J, Jackson, Hibernate Validator, and Tomcat. This is actually a combination of open source libraries that are used in Spring recommended Web apps.


Call the spring boot application Java code, as follows:

import org.springframework.boot.springapplication;import  org.springframework.boot.autoconfigure.enableautoconfiguration;import  org.springframework.web.bind.annotation.requestmapping;import  Org.springframework.web.bind.annotation.RestController, @RestController @enableautoconfigurationpublic  class application {@RequestMapping ("/") String index ()  {return  "www.yoodb.com";} Public static void main (String[] args)  throws exception { Springapplication.run (Application.class, args);}} 

The Application.java class is a simple Web application that can run independently. Running the Java class directly will start an inline Tomcat server running on port 8080. Visit "http://localhost:8080" to see "www.yoodb.com" on the page. You can launch a standalone Web app with just 2 files. There is no need to install Tomcat-like application servers, or to package them into war files. You can start the app on the command line with "MVN Spring-boot:run". The "Org.springframework.boot:spring-boot-maven-plugin" plugin was added to the Pom.xml file. After the plugin is added, when the MVN package is run, it is packaged as a JAR file that can be run directly, and can be run directly using the "Java-jar" command. The deployment of the application is simplified to a large extent and can be run only if the JRE is installed.


The role of the @EnableAutoConfiguration annotation is to allow spring Boot to automatically configure the spring framework based on the dependencies declared by the application, reducing the workload for developers. The annotations "@RestController" and "@RequestMapping" are provided by spring MVC to create a rest service. These two annotations are not related to Spring Boot itself.

Spring boot quickly builds spring framework

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.