Spring Boot快速建立HelloWorld项目

2023-06-07,,

Spring Boot使我们更容易去创建基于Spring的独立和产品级的可以”即时运行“的应用和服务。支持约定大于配置,目的是尽可能快地构建和运行Spring应用。

构建环境

JDK 6+

Maven

创建项目

1.使用Maven创建一个普通Maven应用即可。

2.修改pom.xml文件

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

3.创建java文件SampleController.java

package hello;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

@RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}

4.Run As Java Application

Spring Boot快速建立HelloWorld项目的相关教程结束。

《Spring Boot快速建立HelloWorld项目.doc》

下载本文的Word格式文档,以方便收藏与打印。