1.搭建環(huán)境windows10+jdk1.8+eclipse4.8+maven
2.為了學(xué)習(xí)微服務(wù)架構(gòu)學(xué)習(xí)搭建基礎(chǔ)項(xiàng)目
3.分為兩種搭建方式為maven項(xiàng)目和單獨(dú)建立springboot項(xiàng)目(eclipse需要安裝相關(guān)的插件)
第一種使用maven搭建
1)創(chuàng)建maven項(xiàng)目 file--new---other --maven-project
2) 配置pom文件將springbootz相關(guān)的包引入
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven./POM/4.0.0" xmlns:xsi="http://www./2001/XMLSchema-instance" xsi:schemaLocation="http://maven./POM/4.0.0 http://maven./xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- spring boot基本環(huán)境 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> </parent> <groupId>com.wj</groupId> <artifactId>springboot</artifactId> <version>0.0.1-SNAPSHOT</version>
<name>springboot</name> <!-- FIXME change it to the project's website --> <url>http://www.</url>
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties>
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!--web應(yīng)用基本環(huán)境配置 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
</dependencies>
<build> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.0.0</version> </plugin> <!-- see http://maven./ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.20.1</version> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> <!-- spring-boot-maven-plugin插件就是打包spring boot應(yīng)用的 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin>
</plugins> </pluginManagement> </build> </project>
3)創(chuàng)建先關(guān)的資源文件包 src/main/java 和src/main/resources
4) 創(chuàng)建測(cè)試的類
新建目錄com.springboot和com.spring.web兩個(gè)目錄
在com.wj.spring目錄下新建類App.java
package com.wj.springboot;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
/** * Hello world! * */ @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } }
在com.wj.spring.web下新建類OneController.java
package com.wj.springboot.web;
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;
@Controller public class OneController {
@RequestMapping("/") @ResponseBody public String index() { return "hello spring boot"; } }
5)然后run運(yùn)行App.java啟動(dòng)項(xiàng)目,看日志輸出窗口出現(xiàn)下圖


6)在瀏覽器打開路徑http://localhost:8080出現(xiàn)下邊的圖例

即搭建成功
第二種通過(guò)新建springboot項(xiàng)目創(chuàng)建
1)eclipse安裝springboot相關(guān)插件
首先查看eclispe的版本


然后安裝springboot相關(guān)插件spring-tool-suite
Eclipse --> Help--> Install new Sofware






2)創(chuàng)建項(xiàng)目




3)run運(yùn)行springbootsApplication.java

4)瀏覽器 訪問(wèn)http://localhost:8080
|