自建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;
    }

}
View Code

相关文章:

  • 2022-12-23
  • 2021-04-15
  • 2021-08-14
  • 2022-02-22
  • 2021-06-24
  • 2022-02-17
  • 2021-08-16
  • 2022-12-23
猜你喜欢
  • 2019-08-05
  • 2021-07-12
  • 2021-11-09
  • 2022-12-23
  • 2021-10-21
  • 2021-04-02
  • 2022-01-03
相关资源
相似解决方案