Spring and SpringMVC frameworks, I believe you are familiar with it. In the process of learning and using it, you must find that you need to configure a lot of things, build a good environment, and deploy to the Web container to run properly. It’s gonna take most of the day. To build a microservice architecture, we will break the system into many small projects to provide services. It is such a waste of time to build a project.
Spring Boot allows you to quickly create a Spring-based project that runs perfectly well with very little configuration and doesn’t even need to be deployed to Tomcat. Are you looking forward to it? No more nonsense, let’s get to the point.
Spring Boot core features:
1. Run the Spring project independently
Spring Boot can be run as a jar package, java-jar xxx.jar Wow, a simple command to run a Spring Web service, is not very convenient. Deploying to Docker would be even better.
2. Embedded Servlet container
Wondering why it can provide Web services as jar packages, Spring Boot has Tomcat built into it, eliminating the need to deploy projects as war packages. It’s no mystery, is it? It’s the same thing.
3. Provide the starter to simplify Maven configuration
Using Spring requires adding a large number of dependencies, many of which are fixed, and Spring Boot helps simplify Maven configuration through starter.
4. Automatically configure Spring
5. Application monitoring of quasi-production
6. No code generation and XML configuration
To learn more about the benefits of Spring Boot, follow us!
1. Project creation
First contact, first create a Spring Boot project, take IntelliJ IDEA as an example, choose Spring Initializr when creating, as shown below:
2. Fill in the project details as shown below:
3. Fill in the technology used in the project
Check the corresponding technology as required, isn’t it very convenient, as shown below:
4. As the final step, fill in the project name and click Finish:
The first creation will download the required dependencies and so on, which takes a little longer. Once the project is created, let’s see how this thing works. In the root directory of the project, there will be an entry class ending with Application, as shown below:
This class has an @SpringBootApplication annotation, which is the core annotation of the entire SpringBoot, and its purpose is to enable automatic configuration of SpringBoot.
Create a new IndexController class, add an @restController annotation to the class, and return “Login successful” as follows:
Then click the project launch button to run, which in IntelliJ is the same button:
After successful startup, we can directly access in the browser, as follows:
At this point, a simple Spring Boot project is up and running and accessible from the browser, but why is it finally running? Presumably friends still have many questions, in the next chapter to explain in detail, remember to pay attention to (⊙ O ⊙) oh.