引入依赖
- spring-boot-starter-web
- spring-boot-starter-aop
- spring-boot-starter-security
- spring-boot-starter-actuator
- spring-boot-starter-data-redis
- mybatis-spring-boot-starter
- mysql-connector-java
- com.alibaba.druid
注:由于引用了SpringBoot的父POM,所以此处前五个Spring官方提供的Starter不需要标明版本,而MyBatis的Starter由MyBatis官方实现,故需要标明版本
如果不需要或者需要更改SpringBoot Starter中引入的依赖,可以用exclude来排除依赖或者直接引入其他版本的依赖来覆盖默认依赖
项目结构
项目结构十分类似Spring项目,不同之处在于不见了许许多多包括web.xml在内的XML配置文件,显得清爽、精炼了很多
application.properties/application.yml
properties文件以键值对形式存储数据,此处不再赘述。yml文件更像是支持树结构的键值对记录文件。
SpringBoot会有许多默认的配置实现,而对这些默认配置的更改就是在application.properties中进行配置;
比如SpringSecurity的几项基本配置
security.user.name=name
security.user.password=password
security.basic.path=/*
security.sessions=never
SpringBoot中存在Profile的概念,即可以根据工程所处的不同环境来指定对应环境不同的配置
spring.profiles.active=dev
如上图的工程结构中就有定义了三个properties文件,且显式制定了dev为配置文件
logback.xml
SpringBoot默认支持Logback作为日志记录,并且可以在resource目录下编写logback.xml来实现对logback参数的控制,logback的配置与log4j十分的相似,以下是项目中的简单配置