A brief introduction, startup and deployment of the springboot project

Introduction, startup and deployment of the springboot project

Introduction to springboot

Everyone knows that springboot is developed based on spring, but you must know that springboot is not actually an enhancement of spring functions, but provides a way or tool to quickly use spring.

Springboot collects a large number of third-party libraries. These third-party libraries in Spring Boot applications can almost be used out of the box with zero configuration. Most Spring Boot applications require only a very small amount of configuration code (Java-based configuration). The person can focus more on business logic.
- Benefits
- 1.springboot itself is based on the birth of the spring, it can be said as long as the spring to achieve the function, springboot can achieve powerful.
– 2. Convenient to build projects. We all know that when using spring framework to build projects, many configuration files and various assembly beans are unavoidable. Now springboot has almost realized zero configuration files. It adopts java config method. For configuration, the way of annotation configuration is adopted, which simplifies the original numerous configuration files and greatly improves work efficiency. Complete the configuration file through the two annotations @Configuration and @Bean.
Insert picture description here
– 3. Simplified the maven configuration. Although the emergence of spring 4.0 seems to have achieved no xml configuration, it requires a lot of maven configuration, even reaching hundreds of lines. Nowadays, springboot has collected a large number of third-party libraries. Dependency configuration integrates simple maven configuration. The
Insert picture description here
springboot project will come with some maven configuration when it is created. These configurations have already integrated a large number of dependencies. Developers are no longer required to add time-consuming and labor-intensive dependency configurations.
– 4 Simplified deployment.
Springboot embeds tomcat, which can be found in spring-boot-starter-web,
Insert picture description here
so that the tomcat server is not needed during the development process, and the springboot project can be started directly after the jar is finished. Local tomcat. In other words, after getting the springboot project jar, you can start it on a machine with only jdk.

springboot start

As mentioned above, the springboot project comes with tomcat, so no additional tomcat server is needed for project startup and deployment. The key here is that the springboot project will have a startup class. This is the entrance to the springboot project. The
Insert picture description here
above can see that the startup class needs A key annotation @SpringBootApplication, look at the content behind the modified annotation,

@Target(ElementType.TYPE)            // 注解的适用范围,其中TYPE用于描述类、接口(包括包注解类型)或enum声明
@Retention(RetentionPolicy.RUNTIME)  // 注解的生命周期,保留到class文件中(三个生命周期)
@Documented                          // 表明这个注解应该被javadoc记录
@Inherited                           // 子类可以继承该注解
@SpringBootConfiguration             // 继承了Configuration,表示当前是注解类
@EnableAutoConfiguration             // 开启springboot的注解功能,springboot的四大神器之一,其借助@import的帮助
@ComponentScan(excludeFilters = {    // 扫描路径设置(具体使用待确认)
        @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
        @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
...
}

It can be seen that @SpringBootApplication uses multiple annotations, the most important of which is that
@Configuration uses javaconfig for configuration. The configuration class of the Spring Ioc container
@EnableAutoConfiguration is more important. It is not explained here.
@ComponentScan scanning annotations, automatic scanning And load the components
that meet the conditions. In fact, you can use @SpringBootApplication, or you can use the same three annotations.
Detailed introduction https://www.cnblogs.com/shamo89/p/8184960.html

With these, you can simply understand that when you start a springboot project, you will enter from the startup class entry, automatically scan and load some javaconfig configurations after the @SpringBootApplication annotation, and start the built-in tomcat to run the project.

springboot project deployment

When we used to deploy web projects, we basically wrapped the war package and placed it under the tomcat webapp to start tomcat. This method is not only time-consuming and labor-intensive, but also requires that the server where the project is deployed must have a deployable environment in advance. Sometimes you need to manually modify the tomcat configuration file.
Springboot greatly simplifies the deployment of the project.
We only need to type the project into a jar package, and then put it on the server that only needs jdk, java -jar *** can start the project.

So the question is, we used to deploy web projects in the form of war packages, why can springboot projects be deployed like java applications?

As mentioned above, springboot has built-in tomcat, so when the project starts, tomcat is automatically started, but we all know that the jar file needs to have a main class (main),
yes, it is our startup Since the class is the main class, there will definitely be a start-up class configuration. This is the maven-shade-plugin. Go and find it.
Insert picture description here
Insert picture description here
Sure enough, the problem is solved now. Springboot configures the startup class through the maven plug-in, so you can start the project in the form of java -jar. After the startup class is started, it will scan for the loading configuration and start the built-in tomcat. Finally, the start-up deployment of the project is completed.

The above is a simple understanding of springboot. If there is anything wrong, the other party must correct me! ! !

Guess you like

Origin blog.csdn.net/qq_31142237/article/details/89326765