30.起步依赖

1.起步依赖简介
SpringBoot提供了众多起步依赖来降低项目依赖的复杂度。起步依赖本质上是一个Maven项目对象模型,定义了对其它库的传递依赖,这些依赖的集合可以对外提供某项功能。起步依赖的命名表明它们提供某种或者某类功能,如spring-boot-starter-jdbc表示提供JDBC相关的功能,spring-boot-starter-jpa表示提供JPA相关的功能等。下表列出了项目开发中常用的起步依赖。

名称 描述
spring-boot-starter-parent 常被作为父依赖,提供智能资源过滤、插件设置、编译级别和通用的测试框架
spring-boot-starter-logging 提供Logging相关的日志功能
spring-boot-starter-thymeleaf 使用Thymeleaf视图构造MVC Web应用程序的启动器
spring-boot-starter-web 使用SpringMVC构建Web,包括RESTful应用程序,使用Tomcat作为默认的嵌入式容器的启动器
spring-boot-starter-test 支持常规的测试依赖,包括Junit、Hamcrest、Mockito以及spring-test模块
spring-boot-starter-jdbc 使用JDBC与Tomcat JDBC连接池的启动器
spring-boot-starter-data-jpa 使用Spring JPA与Hibernate的启动器
spring-boot-starter-data-redis Redis key-value数据存储和Spring Dada Redis与Jedis客户端的启动器
spring-boot-starter-log4j2 提供Log4j2相关的日志功能
spring-boot-starter-mail 提供邮件相关功能
spring-boot-starter-activemq 使用Apache ActiveMQ的JMS启动器
spring-boot-starter-data-mongodb 使用MongoDB面向文档的数据库和Spring Dada MongoDB的启动器
spring-boot-starter-actuator 提供应用监控与监控相关的功能
spring-boot-starter-security 使用SpringSecurity的启动器
spring-boot-starter-dubbo 提供Dubbo框架的相关功能

2.排除依赖
事实上,起步依赖和项目里的其它依赖没什么区别。引入起步依赖的同时会引入相关的传递依赖。比如spring-boot-starter-web起步依赖会引入spring-webmvc、jackson-databind、spring-boot-starter-tomcat等传递依赖。如果不想使用spring-boot-starter-web引入的传递依赖,可以使用exclusions标签来排除传递依赖,具体代码如下。


	org.springframework.boot
	spring-boot-starter-web
	
	    
		
			org.springframework.boot
			spring-mvc
		
	

你可能感兴趣的:(从头开始学SpringBoot)