As a program ape, using spring for many years, now has the spring-boot, also wants to try fresh.
At first listen to Spring-boot, feel very mysterious, actually is to assemble a lot of components, plus some boot development of boot and glue program. Personal opinion is not necessarily right.
Build process
Using the spring Initializr, I built it using idea, and there's a spring INITIALIZR option in the new project,
Set the project properties,
Select the Spring-boot component:
Set the project name:
You can do it.
First Program
New Java Program
Package Com.sun.boot;import Org.springframework.boot.springapplication;import Org.springframework.boot.autoconfigure.enableautoconfiguration;import org.springframework.web.bind.annotation.* ; @RestController @enableautoconfigurationpublic class Application { @RequestMapping ("/helloworld") public String Home () { return "Hello world!"; } public static void Main (string[] args) { springapplication.run (application.class, args);} }
View Build.gradle File
Buildscript { ext { springbootversion = ' 1.5.4.RELEASE ' } repositories { mavencentral () } Dependencies { classpath ("Org.springframework.boot:spring-boot-gradle-plugin:${springbootversion}") }} Apply plugin: ' java ' Apply plugin: ' Eclipse ' Apply plugin: ' org.springframework.boot ' version = ' 0.0.1-snapshot ' Sourcecompatibility = 1.8repositories { mavencentral ()}dependencies { compile (' Org.springframework.boot: Spring-boot-starter-web ') runtime (' Mysql:mysql-connector-java ') testcompile (' Org.springframework.boot:spring-boot-starter-test ')}
The program structure is as follows:
Run
Run application with the output as follows:
. ____ _ _ _ _/\\/___ _ _ _ _ (_) _ __ _ \ \ \ (() \___ | ' _ | ' _| | ' _ \ _ ' | \ \ \ \\/ ___)| |_)| | | | | || (_| | ))) ' |____|. __|_| |_|_| |_\__, | ////=========|_|==============|___/=/_/_/_/:: Spring Boot:: (v1.5.4.release) 2017-07-19 08:22:36.552 INFO 837 2---[main] com.sun.boot.Application:Starting application on sunzuoquan-inspiron-7466 with P ID 8372 (/home/sunzuoquan/ideaprojects/demo/build/classes/java/main started by Sunzuoquan in/home/sunzuoquan/ Ideaprojects/demo) 2017-07-19 08:22:36.583 INFO 8372---[main] com.sun.boot.Application:No a Ctive profile set, falling back to default profiles:default2017-07-19 08:22:37.041 INFO 8372---[main] ation Configembeddedwebapplicationcontext:refreshing Org.springframework.boot[email protected]43bd930a:startup Date [Wed Jul 08:22:36 CST 2017]; Root of context hierarchy2017-07-19 08:22:42.185 INFO 8372---[main] s.b.c.e.t.tomcatembeddedservletcontainer:tomcat initialized with Port (s): 8080 (http) 2017-07-19 08:22:42.210 INFO 8372---[main] o.apache.catalina.core.standardservice:starting service [tomcat]2017-07- 08:22:42.211 INFO 8372---[main] org.apache.catalina.core.StandardEngine:Starting Servlet Engine:apach E tomcat/8.5.152017-07-19 08:22:42.747 INFO 8372---[ost-startstop-1] o.a.c.c.c.[tomcat]. [localhost]. [/]: Initializing Spring embedded webapplicationcontext2017-07-19 08:22:42.748 INFO 8372---[ost-startstop-1] O.s . Web.context.ContextLoader:Root Webapplicationcontext:initialization completed in 5760 ms2017-07-19 08:22:42 .877 INFO 8372---[ost-startstop-1] o.s.b.w.servlet.servletregistrationbean:mapping servlet: ' Dispatcherservlet ' to [ /]2017-07-19 08:22:42.880 INFO 8372---[ost-startstop-1] o.s.b.w.servlet.filterregistrationbean:mapping filter: ' Cha Racterencodingfilter ' to: [/*]2017-07-19 08: 22:42.880 INFO 8372---[ost-startstop-1] o.s.b.w.servlet.filterregistrationbean:mapping filter: ' Hiddenhttpmethodfi Lter ' to: [/*]2017-07-19 08:22:42.880 INFO 8372---[ost-startstop-1] o.s.b.w.servlet.filterregistrationbean:mapping Filter: ' Httpputformcontentfilter ' to: [/*]2017-07-19 08:22:42.881 INFO 8372---[ost-startstop-1] O.s.b.w.servlet.filterregistrationbean:mapping filter: ' Requestcontextfilter ' to: [/*]2017-07-19 08:22:43.338 INFO 83 ---[main] s.w.s.m.m.a.requestmappinghandleradapter:looking for @ControllerAdvice: Org.springframework.boo T[email protected]43bd930a:startup Date [Wed Jul 08:22:36 CST 2017]; Root of context hierarchy2017-07-19 08:22:43.401 INFO 8372---[main] s.w.s.m.m.a.requestmappinghandlermapping : Mapped "{[/helloworld]}" onto public java.lang.String com.sun.boot.Application.home () 2017-07-19 08:22:43.405 INFO 837 2---[main] s.w.s.m.m.a.requestmappinghandlermapping:mapped "{[/error],producEs=[text/html]} "onto public org.springframework.web.servlet.ModelAndView Org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml ( Javax.servlet.http.httpservletrequest,javax.servlet.http.httpservletresponse) 2017-07-19 08:22:43.405 INFO 8372--- [main] s.w.s.m.m.a.requestmappinghandlermapping:mapped "{[/error]}" onto public org.springframework.http.Resp Onseentity<java.util.map<java.lang.string, java.lang.object>> Org.springframework.boot.autoconfigure.web.BasicErrorController.error (Javax.servlet.http.HttpServletRequest) 2017-07-19 08:22:43.421 INFO 8372---[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL path [/WEBJ ars/**] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequesthandler]2017-07-19 08:22:43.421 INFO 8372---[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL path [/**] onto handle R of Type [class Org.springframework.web.servlet.resource.ResourceHttpRequesthandler]2017-07-19 08:22:43.440 INFO 8372---[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL Path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequesthandler]2017-07-19 08:22:43.634 INFO 8372---[Mai N] o.s.j.e.a.annotationmbeanexporter:registering beans for JMX exposure on startup2017-07-19 08:22:44.043 INFO 8 372---[main] s.b.c.e.t.tomcatembeddedservletcontainer:tomcat started on port (s): 8080 (http) 2017-07-19 08:2 2:44.065 INFO 8372---[main] com.sun.boot.Application:Started application in 9.217 seconds (JVM running for 15.872)
As can be seen from the log, Tomcat started on port (s): Tomcat was booted inside 8080,spring-boot, listening on port 8080.
Open a browser, visit: Http://localhost:8080/helloworld
The browser output is as follows:
Spring-boo Hello World Program