SpringBoot官網(wǎng)
1劫哼、父pom配置
<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>
<!--父POM文件-->
<groupId>boot.demo</groupId>
<artifactId>microboot</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>microboot</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.8</jdk.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.4.RELEASE</version>
<!--以下兩個(gè)配置為引用程序版本將有springBoot來(lái)進(jìn)行管理-->
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>microboot</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source> <!--源碼的JDK版本-->
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
? 2洋只、 建立microboot的子模塊(module)划乖,建立一個(gè)普通的restfull接口贬养,實(shí)現(xiàn)同樣基礎(chǔ)操作的功能,修改子模塊的pom文件琴庵,追加SpringBoot的Web啟動(dòng)包
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
? 3误算、拷貝SpringBoot官網(wǎng)的啟動(dòng)程序代碼,運(yùn)行測(cè)試
package boot.demo;
/**
* Created by wangjian on 2017/11/4.
*/
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
? 4、啟動(dòng)成功后訪問(wèn):http://localhost:8080,即可看到返回的“Hello World!”