Spring Boot Starter

Source: Internet
Author: User

First, Introduction

The Spring official web site itself is developed using the spring framework, and with the increasing complexity of functionality and business logic, applications are accompanied by a large number of XML configuration files and complex bean dependencies.
With the release of Spring 3.0, the Spring IO Team primary key began to get rid of the XML configuration file, and the idea of "contract first configuration" (Convention over config) was used extensively in the development process to get rid of the complex configurations in the Spring framework , the Java Config is derived.

Spring boot is a development framework that is abstracted in such a context that does not in itself provide the core features and extensions of the spring framework, but only for the rapid and agile development of a new generation of spring framework-based applications. That is, it is not a solution to replace spring, but rather a tool that works closely with the spring framework to enhance the spring developer experience. It also integrates a large number of commonly used third-party library configurations (such as Jackson, JDBC, Mongo, Redis, mail, and so on), and these third-party libraries in the Spring boot application are almost zero-configured out-of-the-box (Out-of-the-box), Most spring boot applications require very little configuration code, and developers can focus more on business logic.

The project is designed to help developers make it easier to create spring-based applications and services, enabling existing and new spring developers to get the spring functionality they need most quickly.

Spring boot does not generate code and requires no XML configuration at all. Its main objectives are as follows:
-Provide a faster, more extensive introductory experience for all spring development efforts.
-Out of the box, you can also change the default values to quickly meet the needs of your project.
-Provides a wide range of common non-functional features in large projects such as embedded servers, security, metrics, health detection, external configuration, and more.

Bo Master prepared to write a set of spring-boot introductory posts, just to give a start, so that the students need to learn how to use Spring-boot, content reference website and online information (http://projects.spring.io/spring-boot/).
Here is the table of contents:

Spring-boot Getting Started Spring-boot controllerspring-boot servletspring-boot filter, listener Spring-boot Interceptor Spring-boot Static resource handling Spring-boot boot Load data spring-boot logging spring-boot Connection Database-JDBC (article writing ... ) Spring-boot Connection Database-JPA (article writing ... ) Spring-boot Connection Database-MyBatis (article writing ... Spring-boot Connection database-Multiple data sources and transactions (in writing ...) Spring-boot Unit Test (article writing ...) Spring-boot Packaging and Deployment (article writing ...) Spring-boot Server Configuration (article writing ...) Spring-boot Web HTTPS (article writing ...) Spring-boot Application Monitoring (article writing ...) )

Development tools: Spring tool Suite v_3.7.2 (STS)
Website address: http://spring.io/tools/sts

Ii. examples of getting started-HelloWorld

File > New > Spring Starter Project

Next > Finish

Project Creation Complete:

As can be seen, the project source code on a Java class, in the Pom.xml have spring-boot-starter-web dependency.

Springbootsampleapplication.java

package org.springboot.sample;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublicclass SpringBootSampleApplication {    publicstaticvoidmain(String[] args) {        SpringApplication.run(SpringBootSampleApplication.class, args);    }}

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>Org.springboot.sample</groupId>    <artifactid>Spring-boot-sample</artifactid>    <version>0.0.1-snapshot</version>    <packaging>Jar</Packaging>    <name>Spring-boot-sample</name>    <description>Spring Boot Sample WEB Application</Description>    <parent>        <groupId>Org.springframework.boot</groupId>        <artifactid>Spring-boot-starter-parent</artifactid>        <version>1.3.1.RELEASE</version>        <relativepath/> <!--lookup parent from repository --    </Parent>    <properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>        <java.version>1.8</java.version>    </Properties>    <dependencies>        <dependency>            <groupId>Org.springframework.boot</groupId>            <artifactid>Spring-boot-starter-web</artifactid>        </Dependency>        <dependency>            <groupId>Org.springframework.boot</groupId>            <artifactid>Spring-boot-starter-test</artifactid>            <scope>Test</Scope>        </Dependency>    </dependencies>    <build>        <plugins>            <plugin>                <groupId>Org.springframework.boot</groupId>                <artifactid>Spring-boot-maven-plugin</artifactid>            </plugin>        </plugins>    </Build></Project>

This completes the creation of the project, and below we create a Hellocontroller.java definition of 3 methods

package Org.Springboot.Sample.ControllerImportJava.Util.ArrayList;ImportJava.Util.HashMap;ImportJava.Util.List;ImportJava.Util.Map;ImportOrg.Springframework.Web.Bind.Annotation.requestmapping;ImportOrg.Springframework.Web.Bind.Annotation.Requestparam;ImportOrg.Springframework.Web.Bind.Annotation.Restcontroller, @RestController @requestmapping ("/hello") PublicClass Hellocontroller {@RequestMapping Public StringHello () {return "Hello spring-boot"; } @RequestMapping ("/info") Public Map<String,String>GetInfo (@RequestParamStringName) {Map<String,String> Map = NewHashMap<>();Map.Put"Name", name);return Map; } @RequestMapping ("/list") Public List<Map<String,String>>GetList () {List<Map<String,String>> List = NewArrayList<>();Map<String,String> Map = NULL; for (int i= 1; I<= 5; I++) {Map = NewHashMap<>();Map.Put"Name","shanhy-" +i);List.AddMap); }return List; }}

You can then run the main method of Springbootsampleapplication directly, just like you do with a normal Java program.
You can then see the spring-boot built-in server container (the default is Tomcat), and all this spring-boot is done for us.

Console output Started springbootsampleapplication in 7.358 seconds (JVM running for 9.154) indicates that the service has been started.

You can see the results by entering our 3 requests in the browser.
Http://localhost:8080/hello
Output: Hello spring-boot
Http://localhost:8080/hello/info?name=shanhy
Output: {"name": "Shanhy"}
Http://localhost:8080/hello/list
Output: [{"Name": "Shanhy-1"},{"name": "Shanhy-2"},{"name": "Shanhy-3"},{"name": "Shanhy-4"},{"name": "Shanhy-5"}]

With our Hello example, I believe you can easily create a project that is as simple as spring-boot to start a service in minutes.
Spring-boot discards cumbersome configuration, allowing developers to focus more on the implementation of business logic. Several of the following articles will be presented to you through examples of various aspects of spring-boot.

Spring Boot Starter

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.