The first spring-boot program and the first spring-boot program

Source: Internet
Author: User

The first spring-boot program and the first spring-boot program

In this example, maven is used as the project management tool.

Create a new pom. xml file and add spring-boot-starter-web dependency:

1 <dependency>2     <groupId>org.springframework.boot</groupId>3     <artifactId>spring-boot-starter-web</artifactId>4     <version>1.5.9.RELEASE</version>5 </dependency>

Pom. xml

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" 3 xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion> 4.0.0 </modelVersion> 5 6 <groupId> com. wangke </groupId> 7 <artifactId> spring-boot-helloworld </artifactId> 8 <version> 1.0 </version> 9 10 <parent> 11 <groupId> org. springframework. boot </groupId> 12 <artifactId> spring-boot-starter-parent </artifactId> 13 <version> 1.5.9.RELEASE </version> 14 </parent> 15 16 <dependencies> 17 <dependency> 18 <groupId> org. springframework. boot </groupId> 19 <artifactId> spring-boot-starter-web </artifactId> 20 </dependency> 21 </dependencies> 22 23 <properties> 24 <java. version> 1.8 </java. version> 25 </properties> 26 27 <build> 28 <plugins> 29 <plugin> 30 <groupId> org. springframework. boot </groupId> 31 <artifactId> spring-boot-maven-plugin </artifactId> 32 </plugin> 33 </plugins> 34 </build> 35 36 </project>Pom. xml

Create a controller

 1 package com.wangke.helloworld; 2  3 import org.springframework.web.bind.annotation.RestController; 4 import org.springframework.web.bind.annotation.RequestMapping; 5  6 @RestController 7 public class HelloController { 8  9   @RequestMapping("/")10   public String index() {11     return "Hello World!";12   }13 }

Create Application class

 1 package com.wangke.helloworld; 2  3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5  6 @SpringBootApplication 7 public class Application { 8    9   public static void main(String[] args) {10     SpringApplication.run(Application.class, args);11   }12 }

Project Structure

Run the program

Mvn clean package & java-jar target/spring-boot-helloworld-1.0.jar

Or

Mvn spring-boot: run

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.