Build a simple springboot environment by yourself

Source: Internet
Author: User

What is Springboot?

Spring boot is commonly known as microservices. Spring Boot is a new framework provided by the pivotal team designed to simplify the initial setup and development of new spring applications. The framework uses a specific approach to configuration, which eliminates the need for developers to define boilerplate configurations. In this way, Spring boot is committed to becoming a leader in the burgeoning field of rapid application development (rapid application development).

1, create a new MAVEN project

Select Workspace First

Click "Next"

Direct default, then click "Next"

Fill in the GroupID etc. ~ then "Finish", to the end of the whole new project here.

2, introduce the relevant jar package

  1  <parent> 2  <groupid>or G.springframework.boot</groupid> 3  <artifactId> Spring-boot-starter-parent</artifactid> 4  <version>1.5.8.release </version> 5  </parent> 6  <            Dependencies> 7  <dependency> 8  <groupid>org.springframework.boot</groupid> 9  <artif Actid>spring-boot-starter-web</artifactid>10  </dependency>< Span style= "COLOR: #008080" >11  </dependencies> 

Here it appears that we only quoted 2 jar packages that actually contain a lot of things, like Spring-boot-starter-web we opened through a zipped package

Looking at the Pom file inside can see the following, it refers to a lot of jars like spring web, and the JSON jar package is included inside the

1<dependencies>2<dependency>3<groupId>org.springframework.boot</groupId>4<artifactId>spring-boot-starter</artifactId>5</dependency>6<dependency>7<groupId>org.springframework.boot</groupId>8<artifactId>spring-boot-starter-tomcat</artifactId>9</dependency>Ten<dependency> One<groupId>org.hibernate</groupId> A<artifactId>hibernate-validator</artifactId> -</dependency> -<dependency> the<groupId>com.fasterxml.jackson.core</groupId> -<artifactId>jackson-databind</artifactId> -</dependency> -<dependency> +<groupId>org.springframework</groupId> -<artifactId>spring-web</artifactId> +</dependency> A<dependency> at<groupId>org.springframework</groupId> -<artifactId>spring-webmvc</artifactId> -</dependency> -</dependencies>

3, writing the Program entry class

1  PackageCom.springbooot2;2 3 Importorg.springframework.boot.SpringApplication;4 Importorg.springframework.boot.autoconfigure.SpringBootApplication;5 6 /**7 * Hello world!8  *9  */Ten @SpringBootApplication One  Public classApp A { -      -      Public Static voidMain (string[] args)throwsException { theSpringapplication.run (App.class, args); -     } -}

Here, @SpringBootApplication is to let the spring scan identify, tell him I am a program entry class.

4, write the Request response class

1  PackageCom.springbooot2;2 3 4 ImportOrg.springframework.stereotype.Controller;5 Importorg.springframework.web.bind.annotation.RequestMapping;6 ImportOrg.springframework.web.bind.annotation.ResponseBody;7  8 @Controller9  Public classFristblood {Ten@RequestMapping ("/fristblood") One @ResponseBody A      PublicString Hello () { -         return"Dont worry,be happy! <br/><br/> <input type=\ "submit\" value=\ "Ok\"/> "; -     } the}

Here's the explanation.

@Controller request processing controller class.

@RequestMapping familiar with spring should be no stranger, this is something of spring, url mapping.

@ResponseBody response method, our response information will be automatically converted to JSON information returned to the foreground page

By the end of the entire code, it was a lot easier to build a framework like SSH or SSM than we did before, if we had the kind that only needed to send a message. or simple service, with Springboot can be said very convenient.

5, test the code

Start the program, open the browser, type:http://localhost:8080/FristBlood

Request page response results such as

Build a simple springboot environment by yourself

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.