由于Spring Boot强大的扫描功能,一些框架只需导入依赖便可使用
整合Web相关框架
SpringBoot会内嵌一个Tomcat服务器,所以只需修改Web相关配置
可以直接在`application.properties`中进行修改,它是整个SpringBoot的配置文件
server.port=80
test.data=100
该配置文件还可以编写自定义的配置项,并在项目中通过`@Value`直接注入
@Controller
public class MainController {
@Value("${test.data}")
int data;
配置文件除了使用`properties`格式以外,还有一种叫做`yaml`或yml格式
一级目录:
二级目录:
三级目录1: 值
三级目录2: 值
三级目录List:
- 元素1
- 元素2
- 元素3
server:
port: 80
整合SpringSecurity依赖
只需要导入SpringSecurity的Starter依赖即可
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
整合Mybatis框架
需要导入对应的starter依赖并加一些配置
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
spring:
datasource:
url: jdbc:mysql://localhost:3306
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
SpringBoot会自动为Mybatis配置数据源,默认使用的就是`HikariCP`数据源
整合Thymeleaf框架
整合Thymeleaf只需导入对应的starter即可
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
这样只能正常解析HTML页面,但是js、css等静态资源需要进行路径指定,不然无法访问
在配文件中配置一下静态资源的访问前缀
spring:
mvc:
static-path-pattern: /static/**
<html lang="en" xmlns:th=http://www.thymeleaf.org
xmlns:sec=http://www.thymeleaf.org/extras/spring-security>