You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 your pom.xml or build.gradle, it does all the heavy lifting for you:
    • Automatically pulls in spring-cloud-sleuth-core as 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.
  • 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 Tracer or SpanManager
    • 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 the starter suffix). 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.
  • spring-data-redis-core: This is the core abstraction layer for Redis. It includes:
    • The foundational RedisOperations interface
    • 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 configure RedisConnectionFactory and RedisTemplate beans 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).

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 13:17:46