1. 程式人生 > >eclipse建立springboot專案的三種方法

eclipse建立springboot專案的三種方法

方法一

安裝STS外掛

安裝外掛導向視窗完成後,在eclipse右下角將會出現安裝外掛的進度,等外掛安裝完成後重啟eclipse生效

 

新建spring boot專案

 

專案啟動

 

方法二

1.建立Maven專案


2.選擇專案型別


3.選擇專案


4.編寫專案組和名稱-finish即可


5.修改pom.xml檔案
<!-- spring boot基本環境 -->

<parent>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-parent</artifactId>

    <version>2.0.2.RELEASE</version>

</parent>

6.pom.xml中新增依賴
<!--web應用基本環境配置 -->

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-web</artifactId>

</dependency>

7.pom.xml中新增編譯外掛
<build>

    <plugins>

    <!-- spring-boot-maven-plugin外掛就是打包spring boot應用的 -->

        <plugin>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-maven-plugin</artifactId>

        </plugin>

    </plugins

</build>

8.基礎包和類


 

9.建立resources資料夾和application.properties檔案


10.App.java
package com.springboot.springbootDemo;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication

public class App

{

    public static void main( String[] args )

    {

        SpringApplication.run(App.class, args);

    }

}

 

11.HelloController.java
package com.springboot.springbootDemo.controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

@RestController

@RequestMapping("hello2")

public class HelloController {

       @RequestMapping("")

       public String hello() {

              return "helloworld2";

       }

}

12.啟動專案


13.訪問專案(低版本可能無法訪問,2版本可用)
http://localhost:8012/hello2

 

方法三

訪問http://start.spring.io/

點選Generate Project下載專案壓縮包

解壓後,使用eclipse,Import -> Existing Maven Projects -> Next ->選擇解壓後的資料夾-> Finsh,OK done!