Spring Boot Starter

Source: Internet
Author: User
Tags aliyun

1. Introduction to Spring Boot

A framework for simplifying spring application development; A large integration of the entire spring technology stack; a one-stop solution for the development of the Java EE;

2. Micro-Service

2014,martin Fowler microservices: Architectural style (service micro) an application should be a small set of services, which can be interoperable via HTTP; single application: All in one microservices: Each functional element is ultimately a software unit that can be independently replaced and independently upgraded;

Micro-Service Documentation:

HTTPS://Martinfowler.com/articles/microservices.html#microservicesandsoa

1, MAVEN settings;

Add and mirror images to the profiles tag of MAVEN's settings.xml configuration file

< Profile><ID>jdk‐1.8</ID><activation><Activebydefault>True</Activebydefault><JDK>1.8</JDK></activation><Properties><Maven.compiler.source>1.8</Maven.compiler.source><Maven.compiler.target>1.8</Maven.compiler.target><maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></Properties></ Profile>

     <Mirrors>        <Mirror>          <ID>Alimaven</ID>          <mirrorof>Central</mirrorof>          <name>Aliyun maven</name>          <URL>http://maven.aliyun.com/nexus/content/groups/public/</URL>        </Mirror>    </Mirrors>

2. Idea setting

Integrate Maven in;

Set Maven's Responsitory repository and maven as your own installed Maven

4. Spring Boot HelloWorld

A function: The browser sends a Hello request, the server accepts the request and processes, responds to the Hello World string;

1. Create a maven project; (JAR)

2. Import Spring boot-related dependencies

<Parent>    <groupId>Org.springframework.boot</groupId>      <Artifactid>Spring‐boot‐starter‐parent</Artifactid>    <version>1.5.9.RELEASE</version></Parent><Dependencies>    <Dependency>      <groupId>Org.springframework.boot</groupId>      <Artifactid>Spring‐boot‐starter‐web</Artifactid>    </Dependency></Dependencies>

3, write a main program; start the spring boot app

/** * @SpringBootApplication to label a main program class, indicating that this is a spring boot application */ @SpringBootApplication  Public class helloworldmainapplication {  publicstaticvoid  main (string[] args) { //    Spring apps start up Springapplication.run (helloworldmainapplication.   Class, args); }}

4, write the relevant controller, Service

@Controller  Public class Hellocontroller {@ResponseBody @requestmapping ("/hello")   public String Hello () { return "Hello world!"  ; }}

5. Run the main program test

6. Simplified deployment

<!‐‐ This plugin, you can package the application into an executable jar package; ‐‐><Build>   <Plugins>      <plugin>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring‐boot‐maven‐plugin</Artifactid>      </plugin>    </Plugins></Build>

This application into a jar package, cmd into the folder, directly using the Java-jar command to execute;

5. Hello World Inquiry

1. pom file

1. Parent Project

<Parent>    <groupId>Org.springframework.boot</groupId>    <Artifactid>Spring‐boot‐starter‐parent</Artifactid>    <version>1.5.9.RELEASE</version></Parent>His father's project is<Parent>    <groupId>Org.springframework.boot</groupId>    <Artifactid>Spring‐boot‐dependencies</Artifactid>    <version>1.5.9.RELEASE</version>    <RelativePath>.. /.. /spring‐boot‐dependencies</RelativePath></Parent>He comes to really manage all dependent versions of the spring boot app;

Spring boot version of the arbitration center; After we import the dependency by default is not required to write the version; (no dependency naturally required to declare version number in dependencies)

2. Starter

< Dependency >    < groupId >org.springframework.boot</groupId>    <  Artifactid>spring‐boot‐starter‐web</artifactid> </ Dependency >

spring-boot-starter-Web: Spring-boot-starter:spring-boot scene launcher;

Help us to import the components that the Web module depends on for normal operation;

Spring boot takes all the feature scenes out and makes them into a starters (launcher), all the dependencies of the starter-related scenarios that are introduced into the project are imported.

What to use to import the launcher of what scene

2. Main program class, main entry class

/** * @SpringBootApplication to label a main program class, indicating that this is a spring boot application */ @SpringBootApplication  Public class helloworldmainapplication {  publicstaticvoid  main (string[] args) { 
   
    // 
     Spring application starts up springapplication.run (helloworldmainapplication. 
      Class
    , args); }}
   

@SpringBootApplication: The Spring boot application callout on a class indicates that the class is Springboot's main configuration class, and Springboot should run the main method of the class to start the Springboot application;

== filtertype.custom, classes = Typeexcludefilter. class  = filtertype.custom, classes = Autoconfigurationexcludefilter. class )}) public @interface springbootapplication {

@SpringBootConfiguration: Spring boot configuration class, labeled on a class, indicates that this is a spring boot configuration class;

@Configuration: This annotation is annotated on the configuration class, the configuration class-----configuration file, and the configuration class is also a component in the container;

@Component @EnableAutoConfiguration: Turn on the automatic configuration feature, the things we need to configure before, Spring boot helps us to configure automatically;

@EnableAutoConfiguration tell Springboot to turn on the automatic configuration function, so that the automatic configuration can take effect;

SOURCE Annotations for @EnableAutoConfiguration

@AutoConfigurationPackage @import (enableautoconfigurationimportselector. class ) public @interface enableautoconfiguration {

@AutoConfigurationPackage: Automatic configuration Package @Import (AutoConfigurationPackages.Registrar.class):

The underlying annotations of spring @Import, importing a component into the container, and importing the components from AutoConfigurationPackages.Registrar.class;

Scan the package of the main configuration class (@SpringBootApplication labeled Class) and all the components in all the sub-packages below to the spring container; (Sometimes the child packages under the spring main program will be scanned)

@Import (enableautoconfigurationimportselector.class); Import components into a container

enableautoconfigurationimportselector: The selector of which components are imported; All components that need to be imported are returned in a full-class name, and the components are added to the container;

A very many automatic configuration classes (xxxautoconfiguration) are imported into the container, and all of the components needed for this scenario are imported into the container, and the components are configured properly;

With the automatic configuration class, we do not have to manually write configuration injection function components, such as work;

Springfactoriesloader.loadfactorynames (Enableautoconfiguration.class,classloader);

Spring boot obtains enableautoconfiguration specified value from meta-inf/spring.factories in the classpath at startup.

import these values as automatic configuration classes into the container, the automatic configuration class will take effect, help us to do the automatic configuration work; we used to configure something ourselves,

Automatic configuration classes help us; the overall integration solution and automatic configuration of the Java EE are spring-boot-autoconfigure-1.5.9.release.jar;

6. Quickly create a spring boot project using spring initializer

1. Idea: Using spring initializer to quickly create a project the IDE supports using the Spring Project Creation Wizard to quickly create a spring boot project;

Select the modules we need; The wizard will create the spring boot project on the Internet; the Spring boot project is generated by default; The main program has been generated.

We just need our own logic.

Directory Structure in Resources folder

Static: All static resources are saved;

JS CSS images; templates: Save All Templates page, (Spring boot default jar package uses embedded tomcat, JSP page is not supported by default); template engine (Freemarker, thymeleaf) can be used;

Application.properties:Spring Boot application configuration file, you can modify some default settings;

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.