SpringBoot Introduction and Getting Started

A, SpringBoot Profile

1.1 Analysis of the advantages and disadvantages of the original Spring

Analysis of the advantages 1.1.1 Spring

Spring is Java Enterprise Edition (Java Enterprise Edition, JEE, also known as J2EE) lightweight substitute. Without developing heavyweight Enterprise JavaBean (EJB), Spring provides a relatively simple method for enterprise Java development, through dependency injection and aspect-oriented programming, using simple Java objects (Plain Old Java Object, POJO) implements EJB function.

Analysis of the shortcomings 1.1.2Spring

Although the Spring component code is lightweight, but its configuration is heavyweight. A beginning, Spring configuration using XML, but also a lot of XML configuration. Spring 2.5 introduces a component scans based annotation, which eliminates a lot for the explicit XML configuration components of the application itself. Spring 3.0 introduces Java-based configuration, which is a type-safe reconfigurable configuration, you can replace XML.

All of these configurations represent a loss during development. Because thinking about Spring features and solutions need to be configured to switch between thinking business problems, so write configuration crowding out the time to write application logic. And all frameworks, Spring and practical, but at the same time it requires a lot of rewards.

In addition, the management of the project is dependent on a time-consuming and labor-intensive thing. When setting up the environment, need to analyze the coordinates of which library you want to import, but also need to analyze coordinate with other libraries have import dependency, dependent upon the wrong version, followed by incompatibility issues will seriously hamper the development progress of the project.

1.2SpringBoot Overview

1.2.1SpringBoot solve the above-mentioned disadvantages of Spring

SpringBoot to improve and optimize the disadvantage of the Spring carried out, based on convention over configuration idea, allowing developers do not have to switch between thinking in configuration and business logic, threw himself into writing code business logic, thereby greatly improving the efficiency of development, shorten the project cycle to some extent.

1.2.2SpringBoot features

For the development of Spring-based experience to provide faster entry

Out of the box, there is no code generation, need not XML configuration. But you can also modify the default values ​​to meet specific needs

It provides a number of large projects in common non-functional properties, such as embedded servers, security, index, health monitoring, external configuration, etc.

SpringBoot not to enhance the functionality of Spring, but provides a way to quickly use the Spring

1.2.3SpringBoot core functionality

Started dependence

Starting rely essentially a Maven project object model (Project Object Model, POM), defines the transitive dependencies on other libraries, these things together which is to support a function.
Simply put, it is to start with some kind of functional dependence coordinates packaged together and provide some default function. Auto Configuration
automatically configures Spring Boot is a run-time (more accurately, when the application starts) process, taking into account many factors before deciding which should be used to configure Spring, which should not be used. This process is done automatically in the Spring.
Note: The start-reliance and the principle of automatic configuration analysis will "SpringBoot principle analysis" explain in detail in Chapter III

Two, SpringBoot Quick Start

2.1 code implementation

2.1.1 Creating the Maven Project

Create a maven project idea to use tool that works for ordinary java project can be
Here Insert Picture DescriptionHere Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

2.1.2 Adding start of dependent SpringBoot

SpringBoot requirements, project start to inherit SpringBoot dependent spring-boot-starter-parent

 <!--所有的springboot工程都必须继承spring-boot-starter-parent-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
    </parent>

SpringBoot to develop integrated SpringMVC Controller, so the project you want to import web start-reliance

<dependencies>
  		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- aop的pom坐标-->
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
     </dependencies>

2.1.3 write SpringBoot bootstrap class

To guide the class started SpringBoot provided by SpringBoot can be accessed

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
 * Created by 54110 on 2019-06-03.
 */
@SpringBootApplication
public class MySpringBootApplication {
    public static void main(String[] args) {
        SpringApplication.run(MySpringBootApplication.class);
    }
}

2.1.4 written Controller

Create QuickStartController guide MySpringBootApplication similar class or sub-packet-level package

package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 54110 on 2019-06-03.
 */
@Controller
public class QuickStartController {

    @RequestMapping("/quick")
    @ResponseBody
    public String quick(){
        return "Spring Boot 访问成功";
    }
}

2.1.5 Testing

.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.1.RELEASE)

2019-06-03 16:57:11.817  INFO 12412 --- [  restartedMain] com.MySpringBootApplication              : Starting MySpringBootApplication on miaohangbo with PID 12412 (D:\project\springboo_qucik\target\classes started by 54110 in D:\project\springboo_qucik)
2019-06-03 16:57:11.818  INFO 12412 --- [  restartedMain] com.MySpringBootApplication              : No active profile set, falling back to default profiles: default
2019-06-03 16:57:11.872  INFO 12412 --- [  restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@62bb93a5: startup date [Mon Jun 03 16:57:11 CST 2019]; root of context hierarchy
2019-06-03 16:57:13.994  INFO 12412 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-06-03 16:57:14.013  INFO 12412 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-06-03 16:57:14.013  INFO 12412 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.29
2019-06-03 16:57:14.020  INFO 12412 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [G:\java1.8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;G:\java1.8\bin;G:\java1.8\jre\bin;G:\python3;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files\Git\cmd;G:\apache-maven-3.5.0\bin;G:\nodejs\;G:\RabbitMqServer\erl9.3\bin;G:\edusoft\ffmpeg-20180227-fa0c9d6-win64-static\bin;G:\OpenSSL-Win64\bin;G:\RabbitMqServer\rabbitmq_server-3.7.8\sbin;G:\Elastic\Ruby25\bin;C:\Users\54110\AppData\Local\Microsoft\WindowsApps;G:\docker\Docker Toolbox;C:\Users\54110\AppData\Roaming\npm;C:\Users\54110\AppData\Local\BypassRuntm;.]
2019-06-03 16:57:14.083  INFO 12412 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-06-03 16:57:14.084  INFO 12412 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2214 ms
2019-06-03 16:57:14.173  INFO 12412 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2019-06-03 16:57:14.176  INFO 12412 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-06-03 16:57:14.176  INFO 12412 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-06-03 16:57:14.176  INFO 12412 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-06-03 16:57:14.176  INFO 12412 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2019-06-03 16:57:14.256  INFO 12412 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-06-03 16:57:14.384  INFO 12412 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@62bb93a5: startup date [Mon Jun 03 16:57:11 CST 2019]; root of context hierarchy
2019-06-03 16:57:14.438  INFO 12412 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/quick]}" onto public java.lang.String com.qf.controller.QuickStartController.quick()
2019-06-03 16:57:14.440  INFO 12412 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-06-03 16:57:14.441  INFO 12412 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-06-03 16:57:14.458  INFO 12412 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-06-03 16:57:14.458  INFO 12412 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-06-03 16:57:14.572  INFO 12412 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2019-06-03 16:57:14.592  INFO 12412 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-06-03 16:57:14.680  INFO 12412 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-06-03 16:57:14.683  INFO 12412 --- [  restartedMain] com.MySpringBootApplication              : Started MySpringBootApplication in 3.164 seconds (JVM running for 3.567)

By logging found, Tomcat started on port (s) : 8080 (http) with context path '' tomcat has been started, the port monitor 8080, web application virtual project name is empty Here Insert Picture Description
Open your browser to access
url address is: http: // localhost : 8080 / quick

Released six original articles · won praise 4 · Views 193

Guess you like

Origin blog.csdn.net/Legend_Young/article/details/103957655