All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.spring.boxes.webhook.starter.push.NotifierAutoConfiguration Maven / Gradle / Ivy

The newest version!
package com.spring.boxes.webhook.starter.push;

import com.spring.boxes.webhook.starter.meta.DingTalkConfig;
import com.spring.boxes.webhook.starter.meta.FeiShuConfig;
import com.spring.boxes.webhook.starter.meta.NotifyConfigure;
import com.spring.boxes.webhook.starter.meta.WechatConfig;
import com.spring.boxes.webhook.starter.push.dingtalk.DingTalkNotifier;
import com.spring.boxes.webhook.starter.push.feishu.FeiShuNotifier;
import com.spring.boxes.webhook.starter.push.wechat.CorpWechatNotifier;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Slf4j
@Configuration
@EnableConfigurationProperties(NotifyConfigure.class)
public class NotifierAutoConfiguration {

    @Autowired
    private NotifyConfigure notifyConfigure;

    @Autowired
    private RestTemplate restTemplate;

   /* @Bean
    @ConditionalOnMissingBean(name = "notifierRestTemplate")
    public RestTemplate notifierRestTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        List> converters = restTemplate.getMessageConverters();
        for (int i = 0; i < converters.size(); i++) {
            if (converters.get(i) instanceof StringHttpMessageConverter) {
                StringHttpMessageConverter converter = (StringHttpMessageConverter) converters.get(i);
                converter.setDefaultCharset(StandardCharsets.UTF_8);
                converters.set(i, converter);
                break;
            }
        }
        restTemplate.setMessageConverters(converters);
        return restTemplate;
    }*/

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass(FeiShuConfig.class)
    public FeiShuNotifier feiShuNotifier() {
        return new FeiShuNotifier(restTemplate, notifyConfigure.getFeiShu());
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass(DingTalkConfig.class)
    public DingTalkNotifier dingTalkNotifier(){
        return new DingTalkNotifier(restTemplate, notifyConfigure.getDingTalk());
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass(WechatConfig.class)
    public CorpWechatNotifier corpWechatNotifier(){
        return new CorpWechatNotifier(restTemplate, notifyConfigure.getCorpWechat());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy