springboot環境快速搭建

爲了後面可視化配置,這裏先配上MAVEN(https://maven.apache.org/download.cgi官網上windows最新zip版的比如:apache-maven-3.6.2-bin.zip

解壓縮即可用,這裏需要在eclipse裏配置一下:

1.Windows->Preference->Maven->Installations:在User Settings裏Browse剛纔解壓縮的根目錄比如:x:\apache-maven-3.6.0\這個目錄(這個目錄裏應該能看到bin、conf等目錄),把勾打上。

2.修改Local Repository,在User setting中browse選擇conf/setting.xml文件,然後點擊藍色的像超鏈接的open file,會在IDE中打開此文件

3.點擊Source,找到文檔裏的這個註釋
    <!-- localRepository | The path to the local repository maven will use to 
        store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> -->

打開註釋改成自己的目錄(可以是任意位置新建的文件夾)

4.(可選),改成國內公庫鏡像提高下載速度,一般是阿里的:

跟上面的修改方式一樣,找到對應註釋位置打開並改成以下內容:

        <mirror>
            <id>alimaven</id>
            <name>aliyunmaven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>

準備工作做完後下載IDE工具(https://spring.io/tools3/sts/legacy,選擇一個版本),本例以32位的STS3.9.6(建議結合自己的環境下載64位最新版的,或其它JAVA EE開發工具)

1.解壓縮即可用(默認已經安裝好JDK1.8及以上),選擇工作空間,在目錄sts-bundle\sts-3.9.6.RELEASE\下雙擊STS即可

2.在Package Explorer中右鍵New->Spring Starter Project

3.以demo爲例僅下一步進入Project Dependencies頁面

4.這裏可以選擇要加載的JAR包,一般JDBC、MyBatis、Mysql、Spring Web Thymeleaf就夠了,不全後期可以在POM.XML中加

5.下一步後應該可以編程了,這時候Pom.xml裏有個紅叉,想去掉的話在pom.xml裏將

<properties>
        <java.version>1.8</java.version>
    </properties>

改成:

<properties>
        <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
        <java.version>1.8</java.version>
    </properties>

然後右鍵工程名——>MAVEN——>Update Project即可

如果這時僅想跑通Controller,把@SpringBootApplication
public class DemoApplication {

改成:

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
public class DemoApplication {

再啓動就不會報錯了,如果以後需要配數據庫還要去掉exclude= {DataSourceAutoConfiguration.class}

這時應該可以在瀏覽器訪問自己寫的Controller了

package com.example.demo.controller;

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

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }
}
 

在瀏覽器中訪問:

http://localhost:8080/hello

頁面效果:

hello

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章