The difference between SpringBoot and SpringMVC
Features of SpringBoot:
1. Simplified configuration
2. Entry-level microframework for microservices
The learning objectives of this article are as follows:
Before learning, you need the following prerequisites:
Notes are as follows:
1. Use cmd to execute the command to view the version of java and maven:
java -version 和 mvn -version
Need to be consistent to avoid differences, Java version 1.8.0_111 , maven version 3.3.9
2. Download the flagship version of idea (which can generate springBoot), which has a 30-day trial period.
1. The first SpringBoot application
1. idea to create a project, the configuration is consistent
The first time to use SpringBoot, it will download a large number of jar packages, which is relatively slow;
Using the default maven configuration will be very slow, but it can be much faster using Ali mirroring.
2. The following is a brief introduction to the project content:
Dependencies in pom file:
GirApplication.java
GirlApplicationTests.java
application.properties is the configuration file of SpringBoot
3. Startup method:
The first one: directly right-click to run
The second: cmd opens the project directory and executes the command:
The third: first compile the program, open the target directory
After the startup is successful, it is normal to directly access 127.0.0.1:8080 and report 404, because nothing was written.
4. Write a controller and access 127.0.0.1:8080/hello
Second, the project properties configuration
1. It is recommended to use a file with a .yml suffix (application.yml), which is relatively simple to write.
2. SpringBoot annotation
Injection of @Value configuration content
or
@Component In order to avoid too much @Value injection, it is recommended to group the configuration and map it with beans
@ConfigurationProperties maps the properties under the corresponding girl prefix
3. Multi-environment configuration
Dev development environment port number: 8080
Prod production environment port number: 8081
Using multiple environments at the same time, you can start dev in idea and start prod in cmd.