javaee experiment: build maven+spring boot development environment and develop "Hello, Spring Boot" application


In development, maven and spring are very commonly used and very important management tools and frameworks. Today I will use idea to build the environment and create the first spring program.

maven

1.1maven is a cross-platform project management tool (mainly managing jar packages)

1.2 It is an open source project of Apache, which mainly serves project construction, dependency management and project information management based on the Java platform. Don’t reinvent the wheel

1.3 Simplicity, communication and feedback, test-driven development (TDD), ten-minute build, continuous integration (CI), and informative workspace. Maven friendly supports almost any software development method; Maven helps to quickly release projects

springboot

SpringBoot is a framework, a brand-new programming specification. Its emergence simplifies the use of the framework. The so-called simplification means simplifying the large number of cumbersome configuration files required in many Spring frameworks. Therefore, SpringBoot is a framework that serves the framework. , the service scope is a simplified configuration file

2.1. Run the Spring project independently

Spring boot can be run independently as a jar package. To run a Spring Boot project, you only need to run java -jar xxx.jar

2.2. Embedded servlet container

Spring Boot can choose to embed Tomcat, jetty or Undertow, so we don’t need to deploy the project in the form of war package

2.3. Provide starter to simplify Maven configuration

Spring provides a series of start pom to simplify Maven dependency loading. For example, when you use spring-boot-starter-web, dependency packages will be added automatically.

2.4. Automatic assembly of Spring

SpringBoot will automatically configure beans for the classes in the jar package based on the jar package in the class path, which will greatly reduce the configuration we need to use. Of course, SpringBoot only considers most development scenarios, not all scenarios. If we need to configure beans in actual development, and SpringBoot does not provide support, we can customize automatic configuration.

2.5. Pre-production application monitoring

SpringBoot provides monitoring of runtime projects based on http ssh telnet

2.6. Codeless production and xml configuration

SpringBoot is not implemented through code generation, but through conditional annotations. This is a new feature provided by Spring 4.x.

3. SpringBoot advantages and disadvantages

Advantages:
3.1. Quickly build projects
3.2. Configuration-free integration of mainstream development frameworks
3.3 , the project can be run independently without external dependence on the Servlet container
3.4. Provide runtime application monitoring
3.5. Greatly improve the development and deployment efficiency a> a> 3.1. If you don’t agree with the spring framework, maybe this is a shortcoming Disadvantages:
3.6. Natural integration with cloud computing

4. SpringBoot features

4.1. Create an independent Spring project
4.2. Built-in Tomcat and Jetty containers
4.3. Provide a starter POMs to simplify Maven configuration 4.5. No code generation and xml at all Configuration file
4.4. Provides a series of non-functional features common in large projects, such as security, indicators, health detection, external configuration, etc.

5. SpringBoot CLI
SpringBoot CLI is the console command tool provided by SpringBoot

Purpose

(1) Master the installation method of Maven
(2) Learn to use idea to integrate Maven to develop Spring Boot projects - "Hello, Spring Boot"

Experiment content

(1) Download and install Maven
(2) Configure Maven with idea
(3) Use idea to build a Spring project based on Maven - " Hello, Spring Boot"

Setting up the environment

This article talks about configuring maven and building the environment in idea
First open idea and create a new project
Insert image description here
Select Spring when creating the project Initializr
Insert image description here
Then click the gear on the right side of the Server URL and set the URL
Insert image description here
to the URL of Alibaba Cloud. Otherwise, if it is the default, the download will be very slow because the default The idea will visit foreign official websites, so the download will be very slow
Insert image description here
When choosing the jdk and java versions, they must correspond to each other on the one hand, and the downloaded maven version on the other hand, otherwise no matter what happens in the future There will be some weird problems when building or running
Insert image description here
After selecting, click next to enter the next interface
Insert image description here
Then notice the spring boot version selection in the upper left corner. You must also choose the version corresponding to the maven version, otherwise the same as above will produce unpredictable results. Because the maven version I downloaded is 3.6.1, the selected version cannot be above 3. Here I chose 2.7.6
Insert image description here
In this project, no more content is needed yet, so click web to select Spring web, and then click create
Insert image description here
After creation, wait for loading to complete, and then the project layout will appear. You can find that demos.web contains the content it automatically generatesInsert image description here
. I almost forgot one thing. After entering the above interface, click file-setting
Insert image description here
to enter this interface.
Insert image description here
Here you need to select the address of the maven you downloaded.
Insert image description here
Then in the user setting file, check override and select the settings.xml in the maven package you downloaded a> This is also to let the idea use local packages instead of visiting foreign official websites, which will make the speed much faster
Insert image description here
Then check the override in the next line and click apply

Run it to test the water
Insert image description here
See the effect
Insert image description here
Try it on the web page and enter your own port number, the author is 9999
Insert image description here

that's all.

Guess you like

Origin blog.csdn.net/m0_72471315/article/details/134196424