Maven依赖
SpringBoot组件
Spring核心组件
- SpringBoot父依赖
在pom文件中定义SpringBoot父依赖则所有Spring依赖都集成父依赖的版本,无需定义版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
</parent>
- SpringBootStarter组件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- SpringBootWeb组件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- SpringBootTest组件(可选)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
- SpringBootAOP组件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
- Thymeleaf模板解析引擎
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
SpringBoot整合其他框架组件
- SpringBoot整合mybatis组件
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
其他依赖
- mysql驱动
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
- apache json工具
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
- lombok
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
SpringBoot配置
以application.yml为例
- 端口及上下文路径
server:
port: 80
servlet:
context-path: /test
- 配置thymeleaf试图模板引擎
spring:
thymeleaf:
mode: HTML
#生产环境建议启用缓存以提高性能
cache: false
suffix: .html
prefix: classpath:/templates/
- 配置数据源
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/databasename?serverTimezone=Asia/Shanghai
username: root
password: root
- Spring多环境配置
以application.yml, application-dev为例,在application.yml文件中配置
spring:
profies:
active:dev
- java 运行jar包时指定环境
java -jar ***.jar --spring.profiles.active=dev