This is the 8th day of my participation in the August More Text Challenge. For details, see:August is more challenging

preface

You can’t write code until you’re fed

With the practice of these days, I found that my understanding of SpringBoot is not satisfactory, and I did not learn a lot, so I intend to learn this recently, while learning while recording!

A brief introduction.

1.1 What is SpringBoot

The way I’m used to is to understand how something comes, what it does and how it is used before I learn it, so that I can have a summarization effect!

1.1.1 The origin of:

SpringBoot comes at a time when Java development has become increasingly cumbersome, requiring a lot of configuration, inefficient development, complicated deployment processes, and difficult to integrate with third-party technologies. In this case, SpringBoot (convention over configuration) is praised for its ability to quickly build projects, configurable integration with mainstream development frameworks, and high development and deployment efficiency without relying on external Servlet containers!

1.1.2 The core function:
- Standalone Spring projects - you can run a standalone SpringBoot project with Java -jar xx.jar - Embedded Servlet container - Embedded Tomcat container, Springt provides a series of Starter POMs to make it easier to load Maven dependencies. For example, when we use spring-boot-starter- Web, Spring - SpringBoot automatically configures beans for classes in jar packages based on the classpath. This greatly reduces the configuration we need to use - pre-production application monitoring - SpringBoot provides monitoring of runtime projects based on HTTP, SSH, Telnet - no code generation and XML configuration - it implements configuration through conditional annotationsCopy the code
1.1.3 The target:

SpringBoot is based on the idea that convention is better than configuration, so that developers do not have to switch between configuration and logical business thinking, fully devoted to logical business code writing, so as to greatly improve the efficiency of development.

1.2 Creating a SpringBoot project

How do you create a SpringBoot project? SpringBoot reads a local TXT file and writes it to the database

1.3 Basic Configuration

1.3.1 Entry class and @SpringBootApplication

The project structure will have an entry class called XXXApplication with a main method, which is similar to the entry methods in Java applications; Used in the main method

SpringApplication.run(XXXApplication.class, args);
Copy the code

To launch the SpringBoot application project. @SpringBootApplication: This is the core annotation SpringBoot, the main combination of @Configuration, @enableAutoConfiguration, @ComponentScan; EnableAutoConfiguration: Enables SpringBoot to automatically configure the current project based on the jar dependencies in the classpath. For example, if spring-boot-starter- Web dependencies are added, Tomcat and SpringMVC dependencies are automatically added, and SpringBoot automatically configures Tomcat and SpringMVC.

1.3.2 custom Banner

When starting a project, there is a default startup pattern:



This is okModify theSRC /main/resources create a banner. Can be achieved byPatorjk.com/software/ta…The site generates the characters you want, copy the generated characters from the site into banner.txt, restart the project, and the pattern will become your custom one.

1.3.3 Global Configuration file

SpringBoot uses a global configuration file application.properties or application.yml; The function is to change some of the default configuration values. For example, when you start several projects, the port number will be used. In this case, you can change the default Tomcat port number. You can add the following to application.yml:

server:
  port: 9999
Copy the code

For example, to change the default access path “/” to “/helloBoot”, add the following to application.yml:

server:
  contextPath: /helloBoot
Copy the code

Tomorrow is Monday, can’t touch fish, today more here! In fact, I think the understanding of SpringBoot should start from the source, such as Spring and SpringMVC; The logic between such should be clearer! Let me get this straight