1, create a MAVEN project, add a parent, the code is as follows
<parent> <groupId>org.springframework.boot</groupId> <artifactId> spring-boot-starter-parent</artifactid> <version>1.3.4.RELEASE</version> </parent >
2. Add a dependency
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies >
3, configure the Java version, if not filled, the default 1.6
<build><!--Configuration Java version is not configured, the default parent class is configured with 1.6--> <pluginManagement> <plugins> < plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> < source>1.7</source> <target>1.7</target> </configuration> </plugin > </plugins> </pluginManagement> </build>
4. Create a new Java file
Packagecom.test;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RestController;/*** @RestController equivalent to @controller and @requestbody **/@RestController @enableautoconfiguration Public classHellocontroller {@RequestMapping ("/hello") PublicString Hello () {return"Hello Word springboot"; } Public Static voidMain (string[] args) {Springapplication.run (hellocontroller.class, args); }}
The last run runs
. ____ _ __ _ _ /\\/___ ' _ __ _ _ (_) _ __ _ \ \ \ (() \___ | ' _ | ' _| | ' _ \ _ ' | \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____|. __|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/: : Spring Boot:: (v1.3.4. RELEASE)2017-08-12 13:51:00.098 INFO 2124---[main] com.test.HelloController:Starting Hellocontroll Er on desktop-m8dr5s3 with PID 2124 (F:\MyEclipse\mywork\spinrBoot-hello\target\classes started by 592302116 in F:\MYECLI pse\mywork\spinrboot-Hello)2017-08-12 13:51:00.113 INFO 2124---[main] com.test.HelloController:No active profile set, Falling Back todefaultProfilesdefault2017-08-12 13:51:00.160 INFO 2124---[main] ationconfigembeddedwebapplicationcontext:refreshing ORG.SPRINGF Ramework.boot[email protected]5b0de4ee:startup Date [Sat 13:51:00 CST 2017]; Root of context Hierarchy2017-08-12 13:51:01.770 INFO 2124---[main] s.b.c.e.t.tomcatembeddedservletcontainer:tomcat initialized wit H Port (s): 8080(HTTP)2017-08-12 13:51:01.815 INFO 2124---[main] o.apache.catalina.core.standardservice:starting service Tomcat2017-08-12 13:51:01.815 INFO 2124---[main] org.apache.catalina.core.StandardEngine:Starting Servlet Engin E:apache tomcat/8.0.332017-08-12 13:51:01.955 INFO 2124---[ost-startstop-1] o.a.c.c.c.[tomcat]. [localhost]. [/]: Initializing Spring embedded Webapplicationcontext2017-08-12 13:51:01.955 INFO 2124---[ost-startstop-1] o.s.web.context.contextloader:root WebApplicationCon Text:initialization completed in 1795Ms2017-08-12 13:51:02.299 INFO 2124---[ost-startstop-1] o.s.b.c.e.servletregistrationbean:mapping servlet: ' disp Atcherservlet ' to [/]2017-08-12 13:51:02.315 INFO 2124---[ost-startstop-1] o.s.b.c.embedded.filterregistrationbean:mapping filter: ' Chara Cterencodingfilter ' to: [/*]2017-08-12 13:51:02.315 INFO 2124---[ost-startstop-1] o.s.b.c.embedded.filterregistrationbean:mapping filter: ' Hidd Enhttpmethodfilter ' to: [/*]2017-08-12 13:51:02.315 INFO 2124---[ost-startstop-1] O.s.b.c.embedded.filterregistrationbean:mapping filter: ' Httpputformcontentfilter ' to: [/*]2017-08-12 13:51:02.315 INFO 2124---[ost-startstop-1] o.s.b.c.embedded.filterregistrationbean:mapping filter: ' Requestcontextfilter ' to: [/* ]2017-08-12 13:51:02.565 INFO 2124---[main] s.w.s.m.m.a.requestmappinghandleradapter:looking for @Controll Eradvice:org.springframework.boot[email protected]5b0de4ee:startup Date [Sat 13:51:00 CST 2017]; Root of context hierarchy2017-08-12 13:51:02.630 INFO 2124---[main] s.w.s.m.m.a.requestmappinghandlermapping : Mapped "{[/hello]}" onto public java.lang.String Com.test.HelloController.hello () 2017-08-12 13:51:02.630 INFO 2124--- [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) 2017-08-12 13:51:02.630 INFO 2124---[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) 2017-08-12 13:51:02.708 INFO 2124--- [main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL path [/webjars/**] onto handler of type [class org . springframework.web.servlet.resource.resourcehttprequesthandler]2017-08-12 13:51:02.708 INFO 2124---[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL Path [/**] onto handler of type [class ORG.SPRINGFRAMEWORK.WEB.SERVL Et.resource.Resourcehttprequesthandler]2017-08-12 13:51:02.802 INFO 2124---[main] o.s.w.s.handler.simpleurlhandlermapping: Mapped URL Path [/**/Favicon.ico] onto handler of type [classOrg.springframework.web.servlet.resource.ResourceHttpRequestHandler]2017-08-12 13:51:02.958 INFO 2124---[main] o.s.j.e.a.annotationmbeanexporter:registering beans forJMX exposure on startup2017-08-12 13:51:03.083 INFO 2124---[main] s.b.c.e.t.tomcatembeddedservletcontainer:tomcat started on port (s): 8080(HTTP)2017-08-12 13:51:03.083 INFO 2124---[main] com.test.HelloController:Started Hellocontrolle R in 3.329 seconds (JVM running for3.61)2017-08-12 13:51:32.885 INFO 2124---[nio-8080-exec-1] o.a.c.c.c.[tomcat]. [localhost]. [/]: Initializing Spring frameworkservlet ' dispatcherservlet ' 2017-08-12 13:51:32.885 INFO 2124---[nio-8080-exec- 1] o.s.web.servlet.dispatcherservlet:frameworkservlet ' Dispatcherservlet ': Initialization started2017-08-12 13:51:32.900 INFO 2124---[nio-8080-exec-1] o.s.web.servlet.dispatcherservlet:frameworkservlet ' disp Atcherservlet ': Initialization completed in MS
In the URL input Http://127.0.0.1:8080/hello
The page will show up
Copyright NOTICE: This article is not the code of the small white original article, without permission shall not be reproduced.
Springboot Getting Started-1 (Hello Word Boot)