Spring Boot Learning route

Source: Internet
Author: User
Tags aop

Spring Boot Learning route, this article plans to analyze and develop a roadmap for learning how to use Spring boot technology based on the author's work and learning experience in recent years.

First, the preparatory work

As the saying goes: "工欲善其事 its prerequisite". In particular, software development, such a focus on the field of engineering practice, we must first select and familiar with a series of development environment tools.

First of all, we recommend the latest version of the technical standards of development tools, the following development environment installation configuration.

Development environment:

(1) JDK 1.8

(2) Eclipse Oxygen EE version or you can also use IntelliJ idea

(3) Tomcat 9

Installation configuration, such as the development tools, you can in the environment, to create a new normal Java project, Dynamic Web Project, a "Hello world" type of starter program, to verify that the environment can be used properly.

Then, you can go to Spring Boot technology learning!

Ii. Introduction to Spring Boot knowledge

To learn and use computer technology knowledge, I suggest integrating theory with practice. In many cases, when we come into contact with a new technology, at the very beginning, must be plagued by the terminology and vocabulary of these technologies, do not understand the definition of these technical terms, concepts, meaning, without these roots, it is difficult to master and learn this technology, and to achieve the degree of convergence.

So, to learn Spring Boot, first of all, from the macro level, to understand the technology its background knowledge, the use of the scene, the development of history, this piece, you can search through the network to a large number of knowledge introduction.

It is recommended to visit Spring official website:https://spring.io/ to get the most authoritative introduction and definition.

Here, I emphasize one thing: Spring boot uses the idea of "Convention over configuration" to provide a contract, default, default configuration for projects created using spring boot, to simplify the development of traditional manual, step-by-step configuration;

Third, Spring basic knowledge of technology

This part of the technical knowledge, is already the Java EE development necessary knowledge. Includes IOC and AOP, with emphasis on the IOC, followed by AOP.

1. Bean Factory

In spring, there is a bean factory. We treat each Java class as a bean (that is, a pea), and spring can be used as a factory (factory), and The Bean Factory (Pea Factory) function is to specialize in producing beans. That is, Spring can go to the production of objects of the class, that is, to instantiate the class object (the new class name ();).

2. Ioc/di control inversion/Dependency Injection

Start with a new dynamic Web project, introduce the latest version of the Spring jar package in the project, configure the use of spring, and familiarize yourself with the Spring Framework's role in the project. Focus on learning about Ioc/di, which is "inversion of control, dependency injection"

Simply to be clear, the IOC produces the cause, and solves the problem.

In the "three Layer structure" (presentation layer, business logic layer, data access layer) architecture development, the class has a call dependency relationship between the layer and the layer

Represents the layer-to-business logic Layer--The data access layer, which represents the method in the layer class that calls the business logic layer class, and the method that calls the data access layer class in the business logic layer class.

To user login, registration, user personal Data maintenance as an example: Design 3 classes Usercontroller, UserService, Userdao, respectively, corresponding to the "three layer structure" of the presentation layer, business logic layer, data access layer.

So, in the actual development code of the project, there are:

In the presentation layer class Usercontroller, to reference userservice:

 Public Class Usercontroller {  new  userservice ();  ...}

In the business logic Layer class UserService, to reference Userdao:

 Public Class userservice {  new  Userdao ();  ...}

We will find that there is a close dependency between classes and classes, that is, in code , a class that references another class and a new object.

In this way, it means that there is a strong coupling. And so, it is not recommended.

Because the software design, it is emphasized that the design of the software needs to have a very good "characteristics:" high cohesion, loose coupling.

In order to understand the decoupling and reduce this strong dependence, the IOC is designed in the Spring framework.

In the code, the dependency between classes and classes is not maintained, that is: Usercontroller does not go to new UserService ()

But to write like this:

 Public Class Usercontroller {  //userservice userservice = new UserService ();   userservice userservice;  ...}

So instantiate UserService, that is, new UserService (); Where do you operate?

To spring's bean factory, to instantiate.

How to instantiate a class object, what needs to be agreed, this requires an XML configuration file to record. Later, you can use annotation (annotations) to configure the properties.

Spring configuration file:

<id= "Cat"  class= "Test.spring.Cat"  scope= " Prototype "><name=" name "  value=" Persian cat "></Property></bean>

3. AOP

Face-cutting programming, mainly to solve the problem of crosscutting.

What is the problem of crosscutting? For example, in development, there are many classes, many methods, classes and classes have a dependency relationship between the call, we call it "top down" linear call. In these codes, it is often necessary to add "Print log" code in many places. And these, the "Print log" of the code, the basic is the same, and "from the bottom" of the linear call, there is no direct business logic relationship. We can call it: Crosscutting into this "top down" linear. It's like a "cross", "vertical", "orthogonal".

In addition to the "log" is a crosscutting issue, "Transaction" also belongs to.

AOP is to solve this crosscutting problem, through configuration, do not let these same code, flooding the project code everywhere. Instead, by using a few configurations, these similar crosscutting codes are configured to where they should appear.

AOP also needs to know some, specialized terminology, we are here simply to introduce, AOP needs to be clear, but also to write special articles, to illustrate and describe.

Iv. Maven, Gradle

To put it simply: both Maven and Gradle solve the same problem, that is, when we create Java-related project projects, we often need to use the. jar packages of various frameworks or class libraries. The traditional way to get started is to go to a dedicated website, download the jar packages, copy and paste them into the project, and then "Add to BuildPath". This can cause some problems.

(1) Some framework jar packages have many, when used in the project, they have a dependency between the jar packages;

(2) and with the migration of time, will continue to introduce new versions, the old and new versions may have conflict issues.

(3) Moreover, a project may use several frameworks, all of which use the same jar packages and how the versions are unified.

(4) The same computer, the creation of multiple projects, each project uses the same framework, the traditional way of the result is that these framework jar package in the computer, copy many times.

......

The advent of Maven and Gradle is to maintain and manage these jar packages. Makes it possible to use these jar packages automatically only by writing a configuration file.

Maven configuration file Pom.xml

<!--Spring begin - <Dependency>      <groupId>Org.springframework</groupId>      <Artifactid>Spring-webmvc</Artifactid>      <version>${spring.version}</version> </Dependency>

V. Spring Boot's Hello World program

In Eclipse, create a Hello world program that uses Spring Boot technology. Go for an initial experience, and touch Spring Boot, with an intuitive feel and impression. It helps to understand and learn to master the technology in the back.

Spring Boot Learning route

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.