Spring Boot

Spring Boot

谨记

依赖

1
2
3
4
5
6
7
8
9
10
11
12
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

启动类

默认使用 spring-boot-starter-tomcat 来运行:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@Controller
@EnableAutoConfiguration
public class HomeController {

@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}

public static void main(String[] args) throws Exception {
SpringApplication.run(HomeController.class, args);
}
}

添加 spring-boot-starter-jetty 切换为 Jetty 启动:

1
2
3
4
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

配置

SpringBoot 使用全局配置 application.propertiesapplication.yml:

1
2
server.port=8082
server.context-path=/hello

日志配置

Profile 配置

名字: application-{profile}.properties

1
2
# application.properties
spring.profiles.active=prod

推荐文章