一、Why is SpringBoot?
-
提供一个快速的Spring项目搭建渠道
-
内嵌服务器,可以快速部署
二、简单项目构建
1、pom引入
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent<artifactId>
<version>2.0.4RELEASE</version>
</parent>
该依赖父类提供了一些Maven的基本配置
2、编写启动类
@EnableAutoConfiguration
@ComponentScan
//@Spring BootConfiguration
public class Application{
public static void main(String[] args){
SpringApplication.run(Application.class,args);
}
}
@EnableAutoConfiguration 表示开启自动化配置
@ComponentScan 扫描当前类(Application)的
所有平级包
或者 @SpringBootApplication 该注解集合了 @EnableAutoConfiguration 和 @ComponentScan 两种注解
3、Tomcat配置(application.properties文件)
a、形式
配置项配置在properties文件中
properties文件可以在以下四个地方进行加载,加载顺序按以下优先级
b、内容
server.port=8081
server.servlet.context-path=/test1
server.error.path=/error
server.tomcat.basedir=/home/temp
server.port : 配置Web容器的端口号
server.servlet.context-path : 配置访问路径
server.tomcat.basedir : 存放Tomcat运行日志和临时文件的目录