Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to treat How Hello World and Hot deployment in Spring Boot 2

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to treat How Hello World and hot deployment in Spring Boot 2? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

We have built a program for HelloWorld. Now, let's take a look at this program. Here are the points we will analyze in this section.

Spring-boot-starter-boot

@ SpringBootApplication

Thermal loading

Spring-boot-starter-boot

Our program is built using maven. If we look at the pom.xml file, we can see that it inherits from this pom, which is a unique part of Maven. What's the use of it?

Java 1.8 is the default compiler level.

UTF-8 coding.

A dependency management section that inherits from spring-boot-dependencies pom and manages versions of generic dependencies. This dependency management can be omitted when using these dependencies in your own pom

< version>

Mark.

Reasonable plug-in configuration (exec plug-ins, git commit id and shade, etc.). I won't talk about it any more. If you want to know more about it, you can send it to see it.

Reasonable resource filtering (e.g. application.properties and application.yml). Contains profile-specific files (for example: application-dev.properties and application-dev.yml)

@ SpringBootApplication

When we look at the BootApplication startup class, we can see that there is a note on the startup class like this:

With an inquisitive attitude, let's take a look at what is included in this annotation class:

You can find that this annotation is composed of multiple annotations (@ SpringBootConfiguration,@EnableAutoConfiguration,@ComponentScan). When SpringBootApplication starts, it scans the current package and subpackages of the main class by default. If you need to scan other packages outside the current package of the main class or do not scan specific packages or classes under the current package, you can set it through the enclosed properties above.

Now let's add this configuration and hold down the ctrl key to locate the package. If we set the property of exclude, we will not add this class to the container managed by Spring. One thing to note here is that the class of exclude must be a class of auto-configuration, otherwise the startup will report an error. As for what auto-configuration is, we will explain it later.

Thermal loading

Next, I would like to introduce a development tool: DevTools, it can greatly improve the efficiency of our development, so how to use it in the environment of IDEA?

Step 1: add dependencies

Step 2: configure the listening path in the configuration file (which can be omitted):

Step 3: change the IDEA settings: first open the settings window and make the following settings

Then, go back to the page and press Ctrl + Shift + Alt + / (Command + Shift + Option + / under Mac), and the following page will appear:

After clicking Registry, the following page will appear for configuration:

Even if it's done here, it's done.

That's all for this article, and we'll continue next week.

The original article is limited in style and shallow in learning. If there are any irregularities in the article, please let me know.

Cloud stroking cat

After reading the above, have you mastered how to view How Hello World and hot deployment in Spring Boot 2? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report