Spring boot development of the first application
1. What is Spring boot?
2. Is spring boot easy to get started with?
Write this article technical articles, mainly to record daily learning and understanding.
We'll meet spring again.
Suppose you were instructed to use spring to develop a simple Hello Word web program.
What should you do? I can think of some basic needs.
1. A project structure, assuming that projects built using MAVEN need to introduce some jar packages
2. A portal for Web. XML starts the file. Configure some startup items inside
3, a class controller, assume that using spring MVC, you need to write a Java class, and configure the properties of Spring MVC
4. A Web server similar to Tomcat. For publishing projects
However, these things are almost essential to every project.
There is only one thing that is related to the Hello Word feature, which is the controller.
All that remains is the generic template that spring has to develop for Web applications.
So can we just write and Hello word-related controllers, and everything else is provided by the framework or something else?
The answer is yes, the answer is: Spring boot
So what exactly is spring boot?
1. First, spring boot is not an application server. It simply embeds a servlet container in the application to enable the Web application to become an executable jar file.
2. Spring boot also does not implement an enterprise Java specification that injects JPA and JMS, but it does support many enterprise Java specifications, but automatically configures the bean that supports those features in spring, such as it does not implement JPA, But it automatically configures a JPA-implemented bean, such as hibernate, to support JPA
3. Spring boot does not introduce any form of code generation, but instead uses the conditional configuration features that look at Spring4, as well as the delivery dependency resolution provided by MAVEN and Gradle, to implement automatic configuration in the context of the spring application.
4. If you do not have spring boot or do not use spring boot, you will do the spring bean configuration yourself. Assuming you're using spring boot, you don't have to write these boilerplate configurations, you can focus on the logic of your application, which is something unique to your application.
These are the basics of understanding Spring boot.
So then let's write a Hello word example.
1. Installing the JDK (omitted)
2. Install IntelliJ Idea (omitted)
3. install maven (omit)
4. After the installation is complete, start creating the project
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/98/3C/wKioL1k4_lfSQYUdAAEAQjAKyL8133.png-wh_500x0-wm_ 3-wmp_4-s_4249329080.png "title=" Ac3f012f-bfe0-4d3b-8735-6df32b72e7cc.png "alt=" wkiol1k4_ Lfsqyudaaeaqjakyl8133.png-wh_50 "/>
Open idea, create a project click Create New Project
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/98/3C/wKioL1k4_rjyFKKpAAFxo4vJU9E102.png-wh_500x0-wm_ 3-wmp_4-s_547872953.png "title="}[) kfti%t3vds]ho[}~o_x3.png "alt=" Wkiol1k4_rjyfkkpaafxo4vju9e102.png-wh_50 "/>
This example takes jdk1.8 as an example
Select Spring INITIALIZR
Select the version of the JDK
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/98/3B/wKiom1k4_0TxrDOmAADCzc7N2Tw571.png-wh_500x0-wm_ 3-wmp_4-s_372349098.png "title="]60mb%{(o2a () v{13i7jf_4.png "alt=" Wkiom1k4_0txrdomaadczc7n2tw571.png-wh_50 "/>
The default name is example,
Let's change it a little bit and change it to demo001
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/98/3C/wKioL1k4_83CU5mcAAEvg3pU1VM053.png-wh_500x0-wm_ 3-wmp_4-s_1563062793.png "title=" Rrra$m ' vmos1@y9kb (PW (2o.png "alt=" wkiol1k4_83cu5mcaaevg3pu1vm053.png-wh_50 "/ >
Interface I have changed, may not be the same as the default, but remember to check the Web
Select the version of Spring boot, I use the 1.4.2 version. did not use 1.5.3
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/98/3C/wKiom1k5AGyQ4WvmAACe80PFNfA486.png-wh_500x0-wm_ 3-wmp_4-s_918642409.png "title=" SF ([V6) {H ' u{}q2b1762 ' 34.png "alt=" Wkiom1k5agyq4wvmaace80pfnfa486.png-wh_50 "/>
Next, the project name is changed to demo001, just like
Project Storage path You can decide for yourself.
650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/98/3C/wKioL1k5AM-CsVd9AAAdOzQ9NQ0522.png-wh_500x0-wm_ 3-wmp_4-s_1749779757.png "title=" Vnql5oni ' $1n) sv27s (g4th.png "alt=" wkiol1k5am-csvd9aaadozq9nq0522.png-wh_50 "/ >
Next is a long wait time for the next package ....
Skips the wait time.
Let's look at the structure of the project we created.
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/98/3C/wKiom1k5AZjDmNV3AABsNNxHGhQ027.png-wh_500x0-wm_ 3-wmp_4-s_1870235807.png "title=" {_gc0u656tk7 ' P2 ' ao9b@]k.png "alt=" wkiom1k5azjdmnv3aabsnnxhghq027.png-wh_50 "/ >
It looks no different than the normal MAVEN project.
Let's take a look at the Pom.xml file
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/98/3C/wKiom1k5AfCSfsovAAGMSDClWu8619.png-wh_500x0-wm_ 3-wmp_4-s_2776171627.png "title=" j0~qf~6) ' kacdsqq ' 8x~yrg.png ' alt= ' wkiom1k5afcsfsovaagmsdclwu8619.png-wh_50 '/ >
Let's write a note, general Maven I will not write, the key is to introduce the description of the dependency package
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/98/3C/wKiom1k5Awjjjgx4AACsdxKDmeo105.png-wh_500x0-wm_ 3-wmp_4-s_4073416976.png "title=" Obljjk ' Guf8nb8sc]vk@h32.png "alt=" wkiom1k5awjjjgx4aacsdxkdmeo105.png-wh_50 "/ >
We'll open it again.
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/98/3D/wKioL1k5A3qQsBt4AADNr1aS5ok657.png-wh_500x0-wm_ 3-wmp_4-s_3318752522.png "title=" _qb) {m6ell3k4e{zqzm[s9b.png "alt=" wkiol1k5a3qqsbt4aadnr1as5ok657.png-wh_50 "/ >
Let's write the notes again.
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/98/3C/wKiom1k5BJbAxWmkAAEGP9kzmW8226.png-wh_500x0-wm_ 3-wmp_4-s_2732656441.png "title=" U0) d~3$4krmc2d@g~f~h7zo.png "alt=" wkiom1k5bjbaxwmkaaegp9kzmw8226.png-wh_50 "/ >
Let's build a new package, create a controller layer Java class
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/98/3D/wKioL1k5BWvS1eCoAAEJEzCMS90430.png-wh_500x0-wm_ 3-wmp_4-s_3106494826.png "title=" Xn$y@~_%or~tlgam1ityyx0.png "alt=" wkiol1k5bwvs1ecoaaejezcms90430.png-wh_50 "/ >
A normal Hello word control layer
Then we directly execute the main method just now, start to see
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/98/3C/wKiom1k5Biyg2TJdAAMlDMcnvYQ519.png-wh_500x0-wm_ 3-wmp_4-s_1870647733.png "title=" Q@2~2ny1) jw39d6 (~tbn@du.png "alt=" wkiom1k5biyg2tjdaamldmcnvyq519.png-wh_50 "/ >
This is the god beast, this starting mode is also ingenious.
And then we visited, the default port at startup is 8080.
Http://localhost:8080/index
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/98/3C/wKiom1k5Br2jbdy0AAAW9rbrJk4220.png-wh_500x0-wm_ 3-wmp_4-s_3792963575.png "title=" A437d6~suw1oi%fuabwfa~e.png "alt=" wkiom1k5br2jbdy0aaaw9rbrjk4220.png-wh_50 "/ >
Just create a controller class and write a few lines of code. can be accessed directly.
The mood is very comfortable to use, no need to configure those tedious XML.
This is the end of the first blog post ...
650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M01/98/3D/wKioL1k5B3ChX-lEAAAQ0hOt0q8778.jpg-wh_500x0-wm_ 3-wmp_4-s_2827673687.jpg "title=" Hls[_ ' dzqr11]oh0020q% (5.jpg "alt=" wkiol1k5b3chx-leaaaq0hot0q8778.jpg-wh_50 "/ >
This article is from the "Green Years" blog, be sure to keep this source http://alex233.blog.51cto.com/8904951/1933490
Spring Boot Learning Series (i)