1.pom.xml 配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2.变更默认的jdk版本
<properties>
<java.version>1.7</java.version>
</properties>
3.update Maven project
4.创建引导类
package cn.itdx.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@SpringBootApplication其实就是以下三个注解的总和
@Configuration: 用于定义一个配置类
@EnableAutoConfiguration :Spring Boot会自动根据你jar包的依赖来自动配置项目。
@ComponentScan:告诉Spring 哪个packages 的用注解标识的类会被spring自动扫描并且装入bean容器。
5.运行
6.用SpringBoot 写个helloworld
package cn.itdx.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
@RequestMapping("/info")
public String info(){
return "HelloWorld";
}
}
7.修改tomcat启动端口
在src/main/resources下创建application.properties
server.port=8088
8.
读取配置文件信息
在src/main/resources下的application.properties 增加配置
url=http://www.itdx.cn
测试
@Autowired
private Environment env;
@RequestMapping("/info")
public String info(){
return "HelloWorld~~"+env.getProperty("url");
}
9.热部署
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>