Spring-Boot 快速入門——Hello World

最近服務(wù)化分布式開發(fā)越來越火,我也加入這個學(xué)習(xí)大軍,準(zhǔn)備寫一系列文章,就當(dāng)是自己的筆記,愿與大家共勉!
重要參考網(wǎng)址:
spring-boot官網(wǎng):https://projects.spring.io/spring-boot/
1、基本環(huán)境搭建
我的電腦環(huán)境配置如下:
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 >chapter1</a>

你喜歡就是我最大的動力——cqf

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容