自建spring-boot-starter
artifactId命名
Spring 官方 Starter通常命名为spring-boot-starter-{name}如 spring-boot-starter-web,
Spring官方建议非官方Starter命名应遵循{name}-spring-boot-starter的格式。
示例以redis为例
1》新建一个maven项目redis-spring-boot-starter,添加pom
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>1.5.9.RELEASE</version> </dependency>
2》添加配置属性
package com.lhx.spring.redis; import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "redis") public class RedisProperties { private String host; private Integer port; public String getHost() { return host; } public void setHost(String host) { this.host = host; } public Integer getPort() { return port; } public void setPort(Integer port) { this.port = port; } }