自定义SpringBoot starter

自定义SpringBoot starter_第1张图片

自定义SpringBoot starter_第2张图片

自定义SpringBoot starter_第3张图片

自定义SpringBoot starter_第4张图片

自定义SpringBoot starter_第5张图片

自定义SpringBoot starter_第6张图片

自定义SpringBoot starter_第7张图片

自定义SpringBoot starter_第8张图片

自定义SpringBoot starter_第9张图片

自定义SpringBoot starter_第10张图片

@imports

https://zhuanlan.zhihu.com/p/618418058

自定义starter原理

https://blog.csdn.net/weixin_45511500/article/details/124571380

全部代码:

package com.it58.demospringbootstater.sms;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.io.Serializable;

@ConfigurationProperties("zzcloud.sms")
public class Sms  implements Serializable{
    //访问ID、即帐号
    private String accessKeyId;
    //访问凭证,即密码å
    private String accessKeySecret;

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public void setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public void setAccessKeySecret(String accessKeySecret) {
        this.accessKeySecret = accessKeySecret;
    }
}

package com.it58.demospringbootstater.sms;

import com.it58.demospringbootstater.service.SmsServiceImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
import javax.annotation.Resource;
 
@Configuration(proxyBeanMethods = false) //表示这个类为配置类
@EnableConfigurationProperties({Sms.class})
public class SmsAutoConfig {
 
    @Resource
    private Sms smsProperties;
 
    @Bean
    public SmsServiceImpl smsServiceImpl(){
 
        return new SmsServiceImpl(smsProperties.getAccessKeyId(),smsProperties.getAccessKeySecret());
    }
 
}

public interface ISmsService {
 
    /**
     * 发送短信
     *
     * @param phone        要发送的手机号
     * @param signName     短信签名-在短信控制台中找
     * @param templateCode 短信模板-在短信控制台中找
     * @param data         要发送的内容
     */
    void send(String phone, String signName, String templateCode, String data);
}
package com.it58.demospringbootstater.service;
 
 

 
public class SmsServiceImpl implements ISmsService {
 
    private String accessKeyId;//访问ID、即帐号
    private String accessKeySecret;//访问凭证,即密码
 
    public SmsServiceImpl(String accessKeyId, String accessKeySecret) {
        this.accessKeyId = accessKeyId;
        this.accessKeySecret = accessKeySecret;
    }
 
    @Override
    public void send(String phone, String signName, String templateCode, String data) {
        System.out.println("接入短信系统,accessKeyId=" + accessKeyId + ",accessKeySecret=" + accessKeySecret);
        System.out.println("短信发送,phone=" + phone + ",signName=" + signName + ",templateCode=" + templateCode + ",data=" + data);
    }
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  com.it58.demospringbootstater.sms.SmsAutoConfig

你可能感兴趣的:(Springboot,spring,boot)