Deploy parent Project
<?XML version= "1.0" encoding= "UTF-8"?><Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupId>Com.hadu.try</groupId> <Artifactid>Try-spring-boot</Artifactid> <Packaging>Pom</Packaging> <version>1.0-snapshot</version> <Modules> <Module>Try-web</Module> </Modules> <!--Inherit defaults from Spring Boot - <Parent> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-starter-parent</Artifactid> <version>1.3.5.RELEASE</version> </Parent></Project>
Create a parent project that allows you to try spring boot next to the module. The default pom:spring-boot-starter-parent for spring boot is introduced in the parent project.
Build a web submodule pom configuration
<?XML version= "1.0" encoding= "UTF-8"?><Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <Parent> <Artifactid>Try-spring-boot</Artifactid> <groupId>Com.hadu.try</groupId> <version>1.0-snapshot</version> </Parent> <modelversion>4.0.0</modelversion> <Artifactid>Try-web</Artifactid> <!--Add Typical dependencies for a Web application - <Dependencies> <Dependency> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-starter-web</Artifactid> </Dependency> </Dependencies> <!--Package as an executable jar - <Build> <Plugins> <plugin> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-maven-plugin</Artifactid> </plugin> </Plugins> </Build></Project>
With the introduction of Spring boot Web boot, the next step in defining a controller is to quickly build a Web program that completely bypasses the complex XML configuration of the Web.
First Controller
/*** Created by Lili on 16/5/16.*/Importorg.springframework.boot.*;ImportOrg.springframework.boot.autoconfigure.*;ImportOrg.springframework.stereotype.*;Importorg.springframework.web.bind.annotation.*; @Controller @enableautoconfiguration Public classSamplecontroller {@RequestMapping ("/") @ResponseBody String Home () {return"Hello world!"; } Public Static voidMain (string[] args)throwsException {springapplication.run (samplecontroller.class, args); }}
The magic of Spring boot is here, and we can go to run like a normal Java program, without having to package the Web app into a Web container such as Tomcat to start the Web App.
Effect Demo
The effect of run up is as follows:
. ____ _ _ _ _/\\/___ _ _ _ _ (_) _ __ _ \ \ \ (() \___ | ' _ | ' _| | ' _ \ _ ' | \ \ \ \\/ ___)| |_)| | | | | || (_| | ))) ' |____|. __|_| |_|_| |_\__, | ////=========|_|==============|___/=/_/_/_/:: Spring Boot:: (v1.3.5.release) 2016-05-17 11:25:28.359 INFO 157 1---[main] samplecontroller:starting Samplecontroller on lilis-macbook-pro.local wi Th PID 1571 (started by Lili in/users/lili/Baidu Cloud Sync disk/gitdir/try-spring-boot) 2016-05-17 11:25:28.364 INFO 1571---[ Main] Samplecontroller:no Active profile set, falling back to default profiles:default2016-0 5-17 11:25:28.522 INFO 1571---[main] ationconfigembeddedwebapplicationcontext:refreshing Org.springframewo Rk.boot[email protected]17baae6e:startup Date [Tue May 11:25:28 CST 2016]; Root of context hierarchy2016-05-17 11:25:31.307 INFO 1571---[main] s.b.c.e.t.tomcatembeddedservleTcontainer:tomcat initialized with Port (s): 8080 (http) 2016-05-17 11:25:31.335 INFO 1571---[main] O.apache . catalina.core.StandardService:Starting service tomcat2016-05-17 11:25:31.337 INFO 1571---[main] Org.apa Che.catalina.core.StandardEngine:Starting Servlet engine:apache tomcat/8.0.332016-05-17 11:25:31.621 INFO 1571---[o ST-STARTSTOP-1] O.a.c.c.c.[tomcat]. [localhost]. [/]: Initializing Spring embedded webapplicationcontext2016-05-17 11:25:31.622 INFO 1571---[ost-startstop-1] O.s . Web.context.ContextLoader:Root Webapplicationcontext:initialization completed in 3109 ms2016-05-17 11:25:32 .243 INFO 1571---[ost-startstop-1] o.s.b.c.e.servletregistrationbean:mapping servlet: ' Dispatcherservlet ' to [ /]2016-05-17 11:25:32.252 INFO 1571---[ost-startstop-1] o.s.b.c.embedded.filterregistrationbean:mapping filter: ' Cha Racterencodingfilter ' to: [/*]2016-05-17 11:25:32.253 INFO 1571---[ost-startstop-1] O.s.b.c.embeDded. Filterregistrationbean:mapping filter: ' Hiddenhttpmethodfilter ' to: [/*]2016-05-17 11:25:32.253 INFO 1571---[Ost-sta RtStop-1] o.s.b.c.embedded.filterregistrationbean:mapping filter: ' Httpputformcontentfilter ' to: [/*]2016-05-17 11:25:32.253 INFO 1571---[ost-startstop-1] o.s.b.c.embedded.filterregistrationbean:mapping filter: ' RequestContextF Ilter ' to: [/*]2016-05-17 11:25:32.925 INFO 1571---[main] s.w.s.m.m.a.requestmappinghandleradapter:looking For @ControllerAdvice: org.springframework.boot[email protected]17baae6e:startup date [Tue 11:25:28 CST 201 6]; Root of context hierarchy2016-05-17 11:25:33.178 INFO 1571---[main] s.w.s.m.m.a.requestmappinghandlermapping : Mapped "{[/]}" onto Java.lang.String samplecontroller.home () 2016-05-17 11:25:33.181 INFO 1571---[main] s. W.s.m.m.a.requestmappinghandlermapping:mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<Java.util.Map<java.lang.string, Java.lang.Object>> Org.springframework.boot.autoconfigure.web.BasicErrorController.error ( javax.servlet.http.HttpServletRequest) 2016-05-17 11:25:33.181 INFO 1571---[main] S.w.s.m.m.a.requestmappingh Andlermapping: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) 2016-05-17 11:25:33.244 INFO 1571--- [main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL path [/webjars/**] onto handler of type [class org . SPRINGFRAMEWORK.WEB.SERVLET.RESOURCE.RESOURCEHTTPREQUESTHANDLER]2016-05-17 11:25:33.244 INFO 1571---[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL Path [/**] onto handler of type [class ORG.SPRINGFRAMEWORK.WEB.SERVL ET.RESOURCE.RESOURCEHTTPREQUESTHANDLER]2016-05-17 11:25:33.302 INFO 1571---[main] o.s.w.s.handler.simpleurlh Andlermapping:mapped URL Path [/**/favicon.ico] onto handler of type [class Org.springframework.web.servlet.resource.ResourceHttpR EQUESTHANDLER]2016-05-17 11:25:33.490 INFO 1571---[main] o.s.j.e.a.annotationmbeanexporter:register ing beans for JMX exposure on STARTUP2016-05-17 11:25:33.618 INFO 1571---[main] s.b.c.e.t.tomcatembeddedserv Letcontainer:tomcat started on port (s): 8080 (http) 2016-05-17 11:25:33.624 INFO 1571---[main] Samplecontro Ller:started Samplecontroller in 6.365 seconds (JVM running for 7.385)
Here's a look at the dependencies of this project:
[INFO] com.hadu.try:try-web:jar:1.0-snapshot[info] \-org.springframework.boot:spring-boot-starter-web:jar:1.3.5. Release:compile[info] +-Org.springframework.boot:spring-boot-starter:jar:1.3.5.release:compile[info] | +-Org.springframework.boot:spring-boot:jar:1.3.5.release:compile[info] | +-Org.springframework.boot:spring-boot-autoconfigure:jar:1.3.5.release:compile[info] | +-Org.springframework.boot:spring-boot-starter-logging:jar:1.3.5.release:compile[info] | | +-Ch.qos.logback:logback-classic:jar:1.1.7:compile[info] | | | +-Ch.qos.logback:logback-core:jar:1.1.7:compile[info] | | | \-Org.slf4j:slf4j-api:jar:1.7.21:compile[info] | | +-Org.slf4j:jcl-over-slf4j:jar:1.7.21:compile[info] | | +-Org.slf4j:jul-to-slf4j:jar:1.7.21:compile[info] | | \-Org.slf4j:log4j-over-slf4j:jar:1.7.21:compile[info] | +-Org.springframework:spring-core:jar:4.2.6.release:compile[info] | \-Org.yaml:snakeyaml:jar:1.16:runtime[info] +-ORG.SPRINgframework.boot:spring-boot-starter-tomcat:jar:1.3.5.release:compile[info] | +-Org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.33:compile[info] | +-Org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.33:compile[info] | +-Org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.33:compile[info] | \-Org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.33:compile[info] +-org.springframework.boot: Spring-boot-starter-validation:jar:1.3.5.release:compile[info] | \-Org.hibernate:hibernate-validator:jar:5.2.4.final:compile[info] | +-Javax.validation:validation-api:jar:1.1.0.final:compile[info] | +-Org.jboss.logging:jboss-logging:jar:3.3.0.final:compile[info] | \-Com.fasterxml:classmate:jar:1.1.0:compile[info] +-com.fasterxml.jackson.core:jackson-databind:jar:2.6.6: Compile[info] | +-Com.fasterxml.jackson.core:jackson-annotations:jar:2.6.6:compile[info] | \-Com.fasterxml.jackson.core:jackson-core:jar:2.6.6:compile[info] +-ORg.springframework:spring-web:jar:4.2.6.release:compile[info] | +-Org.springframework:spring-aop:jar:4.2.6.release:compile[info] | | \-Aopalliance:aopalliance:jar:1.0:compile[info] | +-Org.springframework:spring-beans:jar:4.2.6.release:compile[info] | \-Org.springframework:spring-context:jar:4.2.6.release:compile[info] \-Org.springframework:spring-webmvc:jar : 4.2.6.release:compile[info] \-org.springframework:spring-expression:jar:4.2.6.release:compile
Spring-boot Series: Preliminary spring-boot