Spring Basics: QuickStart Spring Boot (2): Spring INITIALIZR

Source: Internet
Author: User
Tags bind tomcat apache tomcat spring initializr

Spring INITIALIZR is a very effective spring boot when building projects, although Maven and the starter provided by spring boot are very simple to use, but because of the large number of components and associated parts, It is still nice to have such a visual configuration-building management tool. In this article we will use spring INITIALIZR in IntelliJ idea to create a Hello World example program, excluding the speed of Maven downloads, 1 minutes should be enough.

Create a Spring INITIALIZR project

Using IntelliJ idea to create a spring INITIALIZR type project, all default except for choosing Web settings.

Select Web

It is also as convenient to use STS to create starter types without IntelliJ. Neither of them is possible to generate an initial project Zip package using the following connection.

URL https://start.spring.io/

Project Details

After creation, quietly wait for maven to download all dependencies. Take the time to look at what you've created.

As you can see, the right side of the code area highlights is exactly the Springboot entry call.
And underneath the left is what Maven has painstakingly downloaded for us. Pom File

The Pom.xml file is shown below

<?xml version= "1.0" encoding= "UTF-8"?> <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.exam ple</groupid> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> &L T;packaging>jar</packaging> <name>demo</name> <description>demo Project for Spring Boo t</description> <parent> <groupId>org.springframework.boot</groupId> <arti Factid>spring-boot-starter-parent</artifactid> <version>1.4.2.RELEASE</version> <r Elativepath/> <!--lookup parent from repository--> </parent> <properties> <proj Ect.build.sourceencoding>utf-8</project.build.sourceencoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
            <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-web </artifactId> </dependency> <dependency> <groupid>org.springframework .boot</groupid> <artifactId>spring-boot-starter-test</artifactId> <scope>t
            est</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactid


>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

You can clearly see the Web Part we are joining in pendency.

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId> Spring-boot-starter-web</artifactid>
        </dependency>
Modify DemoApplication

Add the following two lines of content

    @RequestMapping ("/") public
    String Hello () {return
        "Hello, Spring Boot ...";
    }

At the same time to DemoApplication plus restcontroller annotation, the revised source is as follows

Package com.example;

Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigure.SpringBootApplication;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication Public
class DemoApplication {
    @RequestMapping ("/")
    public String Hello () {return
        "Hello, Spring Boot ...";
    }
    public static void Main (string[] args) {
        springapplication.run (demoapplication.class, args);
    }
Run

Right-click to run
results confirmed

You can see the results in your browser when you're running.
Console Output

  . ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | ||  (_| | ) ) ) )
  '  |____| .__|_| |_|_| |_\__, |  ////=========|_|==============|___/=/_/_/_/:: Spring Boot:: (v1.4.2.release) 2016-12-03 08:57:58.888 INFO 5128---[main] com.example.DemoApplication:Starting demoapplication on vcc-pc with PID 5128 (C : \users\administrator\ideaprojects\demo\target\classes started by Administrator in C:\Users\Administrator\ Ideaprojects\demo) 2016-12-03 08:57:58.891 INFO 5128---[main] com.example.DemoApplication:No Active profile set, falling back to default Profiles:default 2016-12-03 08:57:58.949 INFO 5128---[main] ati Onconfigembeddedwebapplicationcontext:refreshing Org.springframework.boot.context.embedded.annotationconfigembeddedwebapplicationcontext@30ee2816:startup Date [ Sat Dec 08:57:58 CST 2016]; Root conText Hierarchy 2016-12-03 08:58:00.512 INFO 5128---[main] s.b.c.e.t.tomcatembeddedservletcontainer:tomcat Initialized with Port (s): 8080 (http) 2016-12-03 08:58:00.525 INFO 5128---[main] O.apache.catalina.core.stan Dardservice:starting service Tomcat 2016-12-03 08:58:00.526 INFO 5128---[main] org.apache.catalina.core. Standardengine:starting Servlet engine:apache tomcat/8.5.6 2016-12-03 08:58:00.624 INFO 5128---[ost-startstop-1] o. A.c.c.c.[tomcat]. [localhost]. [/]: Initializing Spring embedded webapplicationcontext 2016-12-03 08:58:00.624 INFO 5128---[ost-startstop-1] o. S.web.context.contextloader:root Webapplicationcontext:initialization completed in 1678 Ms 2016-12-03 08:58:  00.740 INFO 5128---[ost-startstop-1] o.s.b.w.servlet.servletregistrationbean:mapping servlet: ' Dispatcherservlet ' to [/] 2016-12-03 08:58:00.744 INFO 5128---[ost-startstop-1] o.s.b.w.servlet.filterregistrationbean:mapping filtER: ' characterencodingfilter ' to: [/*] 2016-12-03 08:58:00.744 INFO 5128---[ost-startstop-1] o.s.b.w.servlet.filterreg Istrationbean:mapping filter: ' Hiddenhttpmethodfilter ' to: [/*] 2016-12-03 08:58:00.744 INFO 5128---[ost-startstop-   1] o.s.b.w.servlet.filterregistrationbean:mapping filter: ' Httpputformcontentfilter ' to: [/*] 2016-12-03 08:58:00.744 INFO 5128---[ost-startstop-1] o.s.b.w.servlet.filterregistrationbean:mapping filter: ' Requestcontextfilter ' to: [/ *] 2016-12-03 08:58:00.962 INFO 5128---[main] s.w.s.m.m.a.requestmappinghandleradapter:looking for @Contro lleradvice:org.springframework.boot.context.embedded.annotationconfigembeddedwebapplicationcontext@30ee2816: startup Date [Sat Dec 08:57:58 CST 2016]; Root of context hierarchy 2016-12-03 08:58:01.018 INFO 5128---[main] s.w.s.m.m.a.requestmappinghandlermappin G:mapped ' {[/]} ' onto public java.lang.String Com.example.DemoApplication.Hello () 2016-12-03 08:58:01.022 INFO 5128---[main] s.w.s.m.m.a.requestmappinghandlermapping:mapped ' {[/error]} ' onto public org.springframework.h Ttp. Responseentity<java.util.map<java.lang.string, java.lang.object>>
Org.springframework.boot.autoconfigure.web.BasicErrorController.error (Javax.servlet.http.HttpServletRequest) 2016-12-03 08:58:01.022 INFO 5128---[main] s.w.s.m.m.a.requestmappinghandlermapping:mapped "{[/error],prod Uces=[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-12-03 08:58:01.043 INFO 5128--- [main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL path [/webjars/**] onto handler of type [class org  . Springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-12-03 08:58:01.043 INFO 5128---[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL Path [/**] onto handler of type [class Org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-12-03  08:58:01.071 INFO 5128---[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL path [/**/favicon.ico] onto handler of type [class Org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-12-03 08:58:01.174 INFO 5128---[main] o.s.j.e.a.annotationmbeanexporter:registering beans for JMX Exposur E on startup 2016-12-03 08:58:01.226 INFO 5128---[main] S.b.c.e.t.tomcatembeddedservletcontainer:tomcat St              Arted on port (s): 8080 (http) 2016-12-03 08:58:01.230 INFO 5128---[main] com.example.DemoApplication : Started demoapplication in 2.751 seconds (JVM running for 3.109) 2016-12-03 08:58:06.041 INFO 5128---[nio-8080- EXEC-1] O.a.c.c.c.[tomcat]. [localhost]. [/]: Initializing Spring frameworkservlet ' Dispatcherservlet ' 2016-12-03 08:58:06.041 INFO 5128---[nio-8080-exec-1] o.s.web.servlet.dispatcherservlet:frameworkservlet ' dispatcherservlet ': initialization started 2016-12-03 08: 58:06.052 INFO 5128---[nio-8080-exec-1] o.s.web.servlet.dispatcherservlet:frameworkservlet ' DispatcherServlet ' : Initialization completed in one MS

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.