一:搭建
1.环境要求
Java7及以上
Spring Framework4.1.5及以上
2.新建一个maven工程
3.pom.xml(生成)
<!-- 必须引入spring-parent,因为里面实现了很多jar的依赖管理,不需要写jar版本 -->
<!-- spring mvc(这个在springBoot中已经默认集成,只需要添加springboot-web的依赖就行) -->
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 6 <groupId>com.caojun</groupId> 7 <artifactId>springboot</artifactId> 8 <version>0.0.1-SNAPSHOT</version> 9 <packaging>jar</packaging> 10 11 <name>springboot</name> 12 <description>Demo project for Spring Boot</description> 13 14 <parent> 15 <groupId>org.springframework.boot</groupId> 16 <artifactId>spring-boot-starter-parent</artifactId> 17 <version>1.5.8.RELEASE</version> 18 <relativePath/> <!-- lookup parent from repository --> 19 </parent> 20 21 <properties> 22 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 23 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 24 <java.version>1.8</java.version> 25 </properties> 26 27 <dependencies> 28 <dependency> 29 <groupId>org.springframework.boot</groupId> 30 <artifactId>spring-boot-starter-web</artifactId> 31 </dependency> 32 33 <dependency> 34 <groupId>org.springframework.boot</groupId> 35 <artifactId>spring-boot-starter-test</artifactId> 36 <scope>test</scope> 37 </dependency> 38 </dependencies> 39 40 <build> 41 <plugins> 42 <plugin> 43 <groupId>org.springframework.boot</groupId> 44 <artifactId>spring-boot-maven-plugin</artifactId> 45 </plugin> 46 </plugins> 47 </build> 48 49 50 </project>
4.这个时候会出现一个Maven Dependencies
先maven update一下
二:测试
1.对自带的程序进行启动
2.新建java程序
1 package com.caojun.springboot; 2 3 import org.springframework.web.bind.annotation.RequestMapping; 4 import org.springframework.web.bind.annotation.RequestMethod; 5 import org.springframework.web.bind.annotation.RestController; 6 7 @RestController 8 public class HelloSpringBoot { 9 10 @RequestMapping(value="/hello",method = RequestMethod.GET) 11 public String say(){ 12 return "Hello Spring Boot"; 13 } 14 }
3.重新启动
去页面上观察效果
三:maven库