Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Enviar para o telegram

Boa Tarde,

spring:
  application:
    name: '@project.name@'
  profiles:
    active: local
---
spring:
  boot:
    admin:
      notify:
        telegram:
          chat-id: t.me/****
  application:
    name: '@project.name@'
  profiles:
    active: local

server:
  port: 9090
  servlet:
    context-path: /
logging:
  pattern:
  level:
    root: INFO

tentei seguir os paços do codecentric https://codecentric.github.io/spring-boot-admin/2.0.2/#reminder-notifications

import de.codecentric.boot.admin.server.domain.entities.InstanceRepository;
import de.codecentric.boot.admin.server.notify.Notifier;
import de.codecentric.boot.admin.server.notify.RemindingNotifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.time.Duration;

@Configuration
public class NotifierConfiguration {
    @Autowired
    private Notifier notifier;

    @Primary
    @Bean(initMethod = "start", destroyMethod = "stop")
    public RemindingNotifier remindingNotifier() {
        RemindingNotifier notifier = new RemindingNotifier(notifier, repository);
        notifier.setReminderPeriod(Duration.ofMinutes(10));
        notifier.setCheckReminderInverval(Duration.ofSeconds(10));
        return notifier;
    }
}

Só que n sei da onde vem essa variável Repository

3 respostas

Oi Nilton,

Injeta um novo atributo nessa classe:

@Autowired
private InstanceRepository repository;

Veja se assim funciona.

agora ele reclama da variável "notifier" tem de ser inicializada

solução!

Na verdade você vai precisar do exemplo completo, que aparece na sequencia do tutorial:

@Configuration
public class NotifierConfiguration {
    private final InstanceRepository repository;
    private final ObjectProvider<List<Notifier>> otherNotifiers;

    public NotifierConfig(InstanceRepository repository, ObjectProvider<List<Notifier>> otherNotifiers) {
        this.repository = repository;
        this.otherNotifiers = otherNotifiers;
    }

    @Bean
    public FilteringNotifier filteringNotifier() {
        CompositeNotifier delegate = new CompositeNotifier(this.otherNotifiers.getIfAvailable(Collections::emptyList));
        return new FilteringNotifier(delegate, this.repository);
    }

    @Primary
    @Bean(initMethod = "start", destroyMethod = "stop")
    public RemindingNotifier remindingNotifier() {
        RemindingNotifier notifier = new RemindingNotifier(filteringNotifier(), this.repository);
        notifier.setReminderPeriod(Duration.ofMinutes(10));
        notifier.setCheckReminderInverval(Duration.ofSeconds(10));
        return notifier;
    }
}