Spring Boot中STARTER与CORE类型依赖的职责差异解析
Great question! This is a super common confusion when navigating Spring's dependency ecosystem, so let's break it down clearly with your examples.
Starter vs. Core Dependencies: The Core Difference
First, let's set the baseline:
- Starter dependencies are Spring Boot's "one-stop-shop" dependency bundles designed to eliminate boilerplate dependency management. They're essentially dependency aggregators that pull in all the core libraries, auto-configuration classes, and supporting dependencies you need to get a feature up and running quickly.
- Core dependencies are the raw, minimal implementation of a feature. They contain the core API, business logic, and foundational code for the feature, but no auto-configuration or integration with other Spring components out of the box.
Let's use your examples to make this concrete:
Example 1: spring-cloud-starter-sleuth vs spring-cloud-sleuth-core
spring-cloud-starter-sleuth: This is the starter bundle. When you add this to yourpom.xmlorbuild.gradle, it does all the heavy lifting for you:- Automatically pulls in
spring-cloud-sleuth-coreas a dependency - Adds underlying tracing implementations like Brave
- Registers auto-configuration beans to enable distributed tracing (e.g.,
TraceFilter, span management, MDC integration for logs) - You can start generating trace IDs and span IDs in your application with zero manual configuration.
- Automatically pulls in
spring-cloud-sleuth-core: This is the core library. It contains only the foundational tracing logic:TraceContext, span creation/sampling APIs, and core utilities. If you only add this dependency, you'll have to:- Manually add a tracing implementation (like Brave)
- Write your own configuration classes to register beans like
TracerorSpanManager - Handle integration with Spring's web layer, logging, etc., yourself.
This is only useful if you need full control over how tracing is implemented in your app.
Example 2: spring-data-redis vs spring-data-redis-core
spring-data-redis: Think of this as Spring Data Redis's "starter" (even though it doesn't have thestartersuffix). Adding this dependency:- Pulls in
spring-data-redis-core - Includes default Redis client libraries (Lettuce by default, with Jedis as an alternative)
- Enables auto-configuration for
RedisTemplate,StringRedisTemplate, and connection pooling - You can inject these templates into your code and start interacting with Redis immediately.
- Pulls in
spring-data-redis-core: This is the core abstraction layer for Redis. It includes:- The foundational
RedisOperationsinterface - Core serialization and data conversion logic
- Base classes for Redis repositories
But it doesn't include any Redis client implementations or auto-configuration. You'd need to manually add a client (Lettuce/Jedis) and configureRedisConnectionFactoryandRedisTemplatebeans yourself. This is ideal if you need to customize every aspect of your Redis integration (e.g., using a custom client, or non-standard serialization).
- The foundational
What Makes "Core" Dependencies Unique?
To sum up the key traits of core-suffixed dependencies:
- Minimal footprint: They contain only the essential code for the feature, no extra fluff.
- No auto-magic: No auto-configuration beans are registered, so you have full control over setup.
- Dependency-free (mostly): They don't pull in third-party libraries (like tracing implementations or Redis clients), keeping your dependency tree clean.
- Highly customizable: Perfect for advanced use cases where you need to extend or override the core functionality of the feature.
内容的提问来源于stack exchange,提问作者Aditya Rewari
相关产品推荐
相关产品推荐

