1. 程式人生 > >【spring Boot】1.創建第一個springBoot項目

【spring Boot】1.創建第一個springBoot項目

web項目 conf star pen sin ocs frame parent mave

入手springBoot,搭建第一個springBoot項目。

看官方文檔還是有點別扭。

https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-started

================================================================================================================

1.創建一個新的maven項目

maven項目的創建:http://www.cnblogs.com/sxdcgaq8080/p/5586644.html

技術分享

2.配置pom.xml文件

<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.sxd.springBootExample</
groupId> <artifactId>firstSpringBootExample</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <build> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <
configuration> <version>3.0</version> </configuration> </plugin> </plugins> </build> <!-- 引入parent項目,其實就是一個項目jar,版本自己在http://mvnrepository.com/search?q=spring-boot-starter-parent 選擇即可 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.7.RELEASE</version> </parent> <!-- 要跑起來一個web項目,就引入這一個jar即可,版本不用寫,parent中已經聲明了的 --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>

3.創建一個java文件,一個Controller,一個springBoot的主入口

@RequestMapping("/")
訪問的地址:localhost:8080/ 即可。
如果想帶上項目名,請在這裏自行配置上即可。
package com.sxd.main;

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

@RestController
@EnableAutoConfiguration
public class Example {

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

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

}

4.啟動就好

現在不用把項目放入tomcat中,springBoot中嵌入了tomcat

技術分享

5.查看效果

技術分享

瀏覽器上訪問:

技術分享

【spring Boot】1.創建第一個springBoot項目