一:环境搭建
创建maven工程,pom中引入相关依赖
1.定义父类,即公共资源
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> <relativePath /> </parent>
2.定义Java版本
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties>
3.引入相关资源,包含mvc,aop等
<dependencies> <!-- 包含 mvc,aop 等jar资源 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 热部署 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <scope>true</scope> </dependency> </dependencies>
3.引入插件,配置使热部署生效
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!--该配置就是使热部署生效--> <configuration> <fork>true</fork> </configuration> </plugin> </plugins> </build>
4.com.jean.springboot包下创建启动类:
/** * 该启动类就是程序的入口,可以自动装配web的环境 */ @org.springframework.boot.autoconfigure.SpringBootApplication public class SpringBootApplication { public static void main(String[] args) { SpringApplication.run(SpringBootApplication.class,args); } }
5.在com.jean.springboot.controller下定义:
@RestController public class TestController { @RequestMapping("/info") public String sayHi(){ return "HelloWorld"; } }
6.配置tomcat启动,端口8080,直接启动即可,访问地址:http://localhost:8080/info
这是最简单的入门!!!