Writing in the front

In view of the message that someone wants to learn SpringBoot related knowledge, I am going to write a related blog about SpringBoot series, the goal is to let students read this series of blog posts, can have a glimpse of SpringBoot. This preliminary set down a series of blog posts including SpringBoot introduction, introduction, configuration, log, web development, data access, combined with related docker, caching, message queue, retrieve, tasks, security, distributed and so on a series of blog posts, a lot of work, is a long process, every step I have detailed as far as possible, deserve to go up screenshot shows, I hope it’s really useful for those of you who are watching. I just want to share technical blog posts, but also want to say that if you think it is useful, please click on the following, give a like, also a relief to me, after all, I have to lose a lot of hair, hey hey hey

Serial article transport bar

Detailed SpringBoot tutorial introduction (1) detailed SpringBoot tutorial introduction (2) detailed SpringBoot tutorial configuration file (1) detailed SpringBoot tutorial configuration file (2) detailed SpringBoot tutorial log framework Detailed SpringBoot tutorial Web development (1) detailed SpringBoot tutorial Web development (2) detailed SpringBoot tutorial Web development (3) detailed SpringBoot tutorial data access detailed SpringBoot tutorial boot configuration principle Detailed SpringBoot tutorial for cache development

SpringBoot introduction

Let’s start with some concepts that will give us a clearer understanding of the technology. J2EE has cumbersome development, various configuration, low development efficiency, complex deployment process, and difficult integration of third-party technologies. If you have developed SpringMVC or simply used SSH or SSM framework, you must have experienced the fear of being dominated by many configuration files. It is very uncomfortable, but don’t worry. We have SpringBoot. Spring Boot is designed to simplify The development of Spring applications. Just Run creates a standalone, production-level application with more conventions than configurations. With the advent of Spring bucket era, SpringBoot brings us J2EE one-stop solution, and SpringCloud brings us distributed overall solution. Since then, we can use SpringBoot to quickly develop projects based on the Spring framework. Because there are many out-of-the-box Starter dependencies around SpringBoot, it is very convenient for us to develop business code without paying too much attention to the configuration of the framework. Just focus on the business.

SpringBoot advantages

  • Quickly create standalone Spring projects and integrate with mainstream frameworks
  • With the embedded Servlet container, the application does not need to be packaged in a WAR
  • The starters automatically rely on version control
  • A lot of automatic configuration, easy development, also can change the default values
  • No XML configuration, no code generation, out of the box
  • Run time application monitoring for a quasi-production environment
  • Natural integration with cloud computing

See SpringBoot so many advantages, is not very want to immediately use it, not so urgent. SpringBoot is easy to get started with, but it is difficult to master it, because automation helps us integrate Spring buckets so well. If we want to master it, we must understand the technology of Spring buckets. Of course, it is difficult, but since it is easy to use, We can learn how to use it first, and then study the underlying code principles when we are skilled, so that we can have the feeling of opening up.

Micro service

When it comes to SpringBoot, microservices are an architectural style that can be understood as small services that communicate with each other over HTTP. There is no official definition of microservices, so it is difficult to describe microservices directly. We can understand what microservices are by comparing traditional WEB applications. Traditional applications become “single applications”.

Monolithic applications are those where the core is divided into business logic, adapters, and apis or WEB interfaces accessed through the UI. Business logic defines business processes, business rules, and domain entities. Adapters include database access components, message components, access interfaces, and so on, all of which are integrated together and look powerful but messy.

Microservices architecture has a number of important benefits, and it addresses complexity. It breaks down individual applications into a set of services. While the total amount of functionality remains the same, the application has been decomposed into manageable modules or services. These services define explicit RPC or message-driven API boundaries. Microservices architecture reinforces a level of application modularity that is difficult to achieve with a single code base. As a result, microservices are much faster to develop and easier to understand and maintain.

Implement a HelloWord application

Say so many SprigBoot what a good does not directly say no to fit a simple project in the past, then we will run to create a HelloWord applications, some experience from creation to visit http://localhost:8080/hello how simple, You realize how cumbersome the original SpringMVC and SSH and all that stuff is. Here to say, we first get started with a simple application, and then I will explain some SpringBoot configuration and use based on this simple application, is the so-called first to taste the sweetness, just have the motivation to learn, no more nonsense, get started.

The environment that

In fact, there is no need to say more, because the different version I use does not matter too much, but some problems may be caused by the version.

  • Jdk1.8:1.8 is very useful, and most corporate production environment projects are currently 1.8
  • Above SpringBoot1.7: I’m using SpringBoot2.2.4 here
  • Maven3.3 above: I’m using 3.5.4 here
  • Ide-using Idea (Eclipse is fine, but I’m using Idea demo)

Maven is a tool that you can use if you use the built-in Maven for Idea. However, I prefer to use the version I want, so I can configure the version of Maven for Idea myself and also learn something. Maven is also a tool that we must learn about.

I’m using the Idea2018, and the built-in Maven is 3.3. I changed it to 3.5. See my other article about Maven download and installation, as well as installation and configuration

After installing Maven, change the default JDK for Maven to 1.8. In the conf folder of Maven’s installation location, open setting.xml and change it to the following configuration



I’m just going to paste it for your convenience, so you don’t have to type it one by one, as follows

<profile> < ID > JDK-1.8 </ ID > <activation> <activeByDefault>true</activeByDefault> < JDK >1.8</ JDK > </activation> Piler < properties > < maven.com. Source > 1.8 < / maven.com piler source > < maven.com piler. Targer > 1.8 < / maven.com piler targer > The < maven.compiler.com pilerVersion > 1.8 < / maven.compiler.com pilerVersion > < / properties > < / profile >Copy the code

With that done, I will now teach you how to configure your Own Maven using Idea.





Once you’ve made your selection, click Apply.

Realize the function

A function where the browser sends a Hello request and the server accepts and processes the request, corresponding to the HelloWorld string

Specific steps

First we use Idea to create the Maven project









When we first created the Maven project, Idea gave me some tips. We checked this Tip. When we modify the POP.xml, it will automatically load our dependencies.



However, if you do not have Maven life configured, you will find that the loading of Maven dependencies is very slow, because the Maven central library is in a foreign country, so it is naturally slow. We can configure Maven as Alisource, which is much fasterTake you through Maven, installation and configuration, which explains how to configure ali source

Import springBoot-related dependencies

Next, we are going to use poM to load dependencies, load our SpringBoot project, what dependencies should we use, ha ha, don’t worry, here I teach you how to use the official website example, first openSpring’s official website, and then we can check the generated version according to the relevant version we need. Generally, it is ok to select the latest release version of SpringBoot, as shown below



Then we can copy the generated pom.xml dependencies into our project’s pom.xml. Be careful not to copy all of them. Replace the ones I circled with your own, as shown below





So at this point we’re done loading a SpringBoot project, isn’t that easy, but you might say, well, IT’s easy for me to load SpringMVC or something, but don’t worry, let’s write a code, and you’ll see that we don’t have to configure anything.

Write a main program to start the SpringBoot application

Now create a package, create a Java class under the package, name it whatever you like, I’ll call it DemoApplication, as shown below, and write the following code:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        return String.format("Hello %s!", name);
    }
}
Copy the code

You don’t have to do anything, you don’t have to do anything. After you run it, you can access it directly in the browser, and you’ll find it’s successful, comfortable.

SpringBoot simplifies deployment

From creation to operation is so easy, very comfortable, before the code analysis explains, I will say more about SpringBoot sweet, is packaged deployment. When I created Tomcat, I didn’t install and configure it, and I didn’t have a WAR package. How could it run, let alone deploy it? Ha ha ha this time can reflect the small sweetness of SpringBoot, SpringBoot project can be made into a JAR package, and then in the case of no need to install the operating environment, you can directly run the JAR package, start the program, portability is very strong. We can use Maven command to package, or we can directly use Idea to package, Maven command can be directly searched online, here I demonstrate the convenience of using Idea package, the specific operation is as follows, in the Idea sidebar there are Maven Projects, click open:



Wait for the run to end, in the log, as shown below





Paste the jar package into your desktop, open the command line, and execute the command.







Run successfully, and then directly in the browser can be accessed successfully, isn’t it interesting.

The next article

The next chapter will analyze the above code, and then compare the differences between SpringMVC and SpringBoot projects we used before. That way we can start conceptually.