征服SpringSpringBoot极简教程 · Spring Boot spring-boot&spring-cloud系列专题

Spring-Boot 快速入门——Hello World

2017-05-16  本文已影响122人  cqf_

最近服务化分布式开发越来越火,我也加入这个学习大军,准备写一系列文章,就当是自己的笔记,愿与大家共勉!
重要参考网址:
spring-boot官网:https://projects.spring.io/spring-boot/
1、基本环境搭建
我的电脑环境配置如下:
Version: Neon.3 (4.6.3)
maven插件安装
java sdk 1.8.0_131
apache-tomcat-8.0.43
2、新建maven项目
直接上图,如果对maven不熟悉的,需要了解一下maven的基本使用。

maven-creater1.PNG maven-creater2.PNG

这样一个,maven项目就建成了。

2、引入spring-boot依赖库
在pom.xml中引入spring-boot的依赖库

<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.cqf.chapter1</groupId>
<artifactId>chapter1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>chapter1</name>
<description>Spring Boot start first demo</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.2.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
</project>

3、启动类编写

package com.cqf.chapter1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 
 * @author qifu.chen
 * @version 1.0.0
 * @date May 15, 2017 10:53:38 AM
 */
@Controller
@SpringBootApplication
public class Application {

    @RequestMapping("/hello")
    @ResponseBody
    public String hello() {
        return "Hello World!";
    }
    public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
    }
}

4、运行启动类,启动成功后,在浏览器中输入localhost:8080/hello,即可查看到Hello World

具体详见demo <a href="https://github.com/qifuchen/cqf-demo">chapter1</a>

你喜欢就是我最大的动力——cqf

上一篇下一篇

猜你喜欢

热点阅读