Springboot Getting Started Program

Source: Internet
Author: User
Tags apache tomcat

Springboot simplifies many of the XML files before, does not require a large number of configuration XML files, not many XML files is how happy

The following goes to the chase, demonstrating a simple starter program, albeit simple but enough to rouse beginners

My new project is called Hello, you can refer to

First, build a war project and import the right dependencies

<project xmlns= "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.springboot.demo</groupId> <artifactId>   Hello</artifactid> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter        -parent</artifactid> <version>1.3.4.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId> Spring-boot-starter-web</artifactid> </dependency> </dependencies><build><plugins> <plugin><groupid>org.apache.maven.plugins</groupid><artifactid>maven-compiler-plugin</artifactid><version>2.0.2</version>< configuration><source>1.8</source><target>1.8</target></configuration></ Plugin></plugins></build></project>

Second, build the package to build Java file

 Packagecom.example;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;Importorg.springframework.web.bind.annotation.ResponseBody, @Controller @enableautoconfiguration Public classHellocontroller {@RequestMapping ("/hello") @ResponseBody String Home () {return"Hello,spring boot!"; }              Public Static voidMain (string[] args) {Springapplication.run (hellocontroller.class, args); }}

Third, execute the main method inside the Hellocontroller

Appears as shown, indicating successful start

  . ____ _ _ _ _/\\/___ _ _ _ _ (_) _ __ _ \ \ \ (() \___ | ' _ | ' _| | ' _ \ _ ' | \ \ \  \\/  ___)| |_)| | | | | ||  (_| | ))) ' |____|. __|_| |_|_| |_\__, | ////=========|_|==============|___/=/_/_/_/:: Spring Boot:: (v1.3.4.release) 2017-12-24 18:45:26.059 INFO 133 ---[main] com.example.HelloController:Starting Hellocontroller on LAPTOP-AP8KJEQL with PID 1 3340 (E:\Demo\workspace\hello\target\classes started by Eluzhu in E:\Demo\workspace\hello) 2017-12-24 18:45:26.061 INFO 13340---[main] com.example.HelloController:No active profile set, falling back to default Prof iles:default2017-12-24 18:45:26.086 INFO 13340---[main] Ationconfigembeddedwebapplicationcontext:refreshi ng Org.springframework.boot[email protected]24b1d79b:startup Date [Sun Dec 18:45:26 CST 2017]; Root of context hierarchy2017-12-24 18:45:27.110 INFO 13340---[main] s.b.c.e.t.tOmcatembeddedservletcontainer:tomcat initialized with Port (s): 8080 (http) 2017-12-24 18:45:27.121 INFO 13340---[           Main] o.apache.catalina.core.standardservice:starting service tomcat2017-12-24 18:45:27.122 INFO 13340---[ Main] org.apache.catalina.core.StandardEngine:Starting Servlet engine:apache tomcat/8.0.332017-12-24 18:45:27. 241 INFO 13340---[ost-startstop-1] o.a.c.c.c.[tomcat]. [localhost]. [/]: Initializing Spring embedded webapplicationcontext2017-12-24 18:45:27.242 INFO 13340---[ost-startstop-1] o. S.web.context.contextloader:root Webapplicationcontext:initialization completed in 1158 ms2017-12-24 18:45:2  7.486 INFO 13340---[ost-startstop-1] o.s.b.c.e.servletregistrationbean:mapping servlet: ' Dispatcherservlet ' to [/]2017-12-24 18:45:27.490 INFO 13340---[ost-startstop-1] o.s.b.c.embedded.filterregistrationbean:mapping filter: ' Characterencodingfilter ' to: [/*]2017-12-24 18:45:27.490 INFO 13340---[ost-startstop-1] o.s.b.c.embedded.filterregistrationbean:mapping filter: ' Hiddenhttpmethodfilter ' to: [/*]2017-12-24 18:45:27.490 INFO 13340---[ost-startstop-1] o.s.b.c.embedded.filterregistrationbean:mapping filter: ' HttpPutFormCon Tentfilter ' to: [/*]2017-12-24 18:45:27.490 INFO 13340---[ost-startstop-1] o.s.b.c.embedded.filterregistrationbean:m Apping filter: ' Requestcontextfilter ' to: [/*]2017-12-24 18:45:27.679 INFO 13340---[main] s.w.s.m.m.a.reques Tmappinghandleradapter:looking for @ControllerAdvice: org.springframework.boot[email protected]24b1d79b: startup Date [Sun Dec 18:45:26 CST 2017]; Root of context hierarchy2017-12-24 18:45:27.728 INFO 13340---[main] s.w.s.m.m.a.requestmappinghandlermappin           G:mapped "{[/hello]}" onto Java.lang.String com.example.HelloController.home () 2017-12-24 18:45:27.731 INFO 13340---[ 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-12-24 18:45:27.731 INFO 13340---[main] s.w.s.m.m.a.requestmappinghandlermapping:mapped "{[/error],pro Duces=[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-12-24 18:45:27.751 INFO 13340-- -[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL path [/webjars/**] onto handler of type [Class O rg.springframework.web.servlet.resource.resourcehttprequesthandler]2017-12-24 18:45:27.751 INFO 13340---[Mai N] o.s.w.s.handler.simpleurlhandlermapping:mapped URL path [/**] onto handler of type [class org.springframework.web.se Rvlet.resource.resourcehttprequesthandler]2017-12-24 18:45:27.775 INFO 13340---[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL path [/**/favicon.ico] onto H  Andler of type [class org.springframework.web.servlet.resource.resourcehttprequesthandler]2017-12-24 18:45:27.839 INFO 13340---[main] o.s.j.e.a.annotationmbeanexporter:registering beans for JMX exposure on startup2 017-12-24 18:45:27.901 INFO 13340---[main] s.b.c.e.t.tomcatembeddedservletcontainer:tomcat started on port (s): 8080 (http) 2017-12-24 18:45:27.904 INFO 13340---[main] Com.example.HelloController:Start Ed Hellocontroller in 2.094 seconds (JVM running for 2.468)

Four, the third step after the successful implementation, in the browser input Localhost:8080/hello can see hello,springboot this sentence, it means the entry process has been successful

Last note: Springboot far more than this point of function, there are many, explore it together

Springboot Getting Started Program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.