全部学科
NodeJS全栈
nodejs
Python全栈
python
小程序首页
📅 2026-05-18 4 分钟 ✍️ juanwangdev

Spring Boot 自定义Starter命名规范

遵循Spring Boot官方命名规范,使Starter易于识别和使用。

官方Starter命名

Spring Boot官方Starter命名格式:spring-boot-starter-*

Starter说明
spring-boot-starter-webWeb开发
spring-boot-starter-data-jpaJPA数据访问
spring-boot-starter-securitySpring Security
spring-boot-starter-actuator监控端点
spring-boot-starter-test测试支持

第三方Starter命名

第三方Starter命名格式:*-spring-boot-starter

XML
<!-- 正确命名 -->
<artifactId>my-spring-boot-starter</artifactId>
<artifactId>redis-client-spring-boot-starter</artifactId>

<!-- 错误命名(与官方命名冲突) -->
<artifactId>spring-boot-starter-my</artifactId>

第三方Starter必须以-spring-boot-starter结尾,避免与官方Starter混淆。

模块命名约定

单模块结构

XML
my-spring-boot-starter/
├── pom.xml
└── src/
    └── main/
        ├── java/
        └── resources/
            └── META-INF/
                └── spring.factories

多模块结构

推荐将自动配置与Starter分离:

Java
my-spring-boot/               # 父模块
├── my-spring-boot-starter/   # Starter模块(依赖管理)
└── my-spring-boot-autoconfigure/  # 自动配置模块(实际实现)
Java
<!-- my-spring-boot-starter/pom.xml -->
<dependencies>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>my-spring-boot-autoconfigure</artifactId>
    </dependency>
</dependencies>

包命名规范

properties
// 推荐包结构
com.example.my.autoconfigure  // 自动配置类
com.example.my.properties     // 配置属性类
com.example.my.service        // 服务实现类

配置属性命名

text
@ConfigurationProperties(prefix = "my.service")
// 对应配置:my.service.xxx

// 第三方Starter使用公司/项目名作为前缀
@ConfigurationProperties(prefix = "company.project.feature")

Spring Boot 2.7+ 新规范

text
# 新文件位置:META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
# 内容:每行一个配置类全限定名
com.example.autoconfigure.MyAutoConfiguration

常见命名错误

错误命名正确命名
spring-boot-starter-myappmyapp-spring-boot-starter
my-startermy-spring-boot-starter
myapp-boot-startermyapp-spring-boot-starter

要点总结

  • 官方Starter:spring-boot-starter-*
  • 第三方Starter:*-spring-boot-starter
  • 推荐模块分离:starter + autoconfigure
  • 配置属性前缀使用项目名开头
  • 遵循规范便于识别和管理

📝 发现内容有误?点击此处直接编辑

← 上一篇 Spring Boot spring.factories配置
下一篇 → Spring Boot 自定义Starter测试
想查看更多题目和详细解析?
小程序提供完整的题库、模拟考试和详细解析
马上就来

长按或扫描二维码,立即体验

扫码体验小程序
马上就来
使用微信扫描二维码
立即体验完整题库