14
Фев
2020

Корректное завершение spring boot Application

Есть приложение на spring boot

@EnableScheduling
@SpringBootApplication
@PropertySource("classpath:application.properties")
public class Application {
    private static final Logger log = Logger.getLogger(Application.class);

    @Value("${executor}")
    private String executorName;

    @Autowired
    public void setExecutorName(ApplicationContext context) {
        context.getBean(executorName);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

которое запускает Scheduler

@Service("exporter")
@PropertySource("classpath:application.properties")
public class ExecutorExporterService {

    @Value("${topicName}")
    String topicName;

    @Autowired
    EntityRepository entityRepository;

    @Autowired
    ConsumerKafka consumerKafka;

    @Transactional
    @Scheduled(fixedRateString = "${timeInterval}")
    public void runExecutor() throws InterruptedException, ExecutionException {
        Set<ConsumerRecord> consumerRecords = consumerKafka.consumeKafka(Collections.singletonList(topicName));

        List<Person> persons = consumerRecords.stream().map(record -> (Person) record.value()).collect(Collectors.toList());

        entityRepository.saveAll(persons);

        consumerKafka.commitSyncConsumer();
        consumerKafka.closeConsumer();
        System.out.println(persons);
    }
}

запускаю mvn spring-boot:start

пытаюсь остановить: mvn spring-boot:stop

выдает:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.4.RELEASE:stop (default-cli) on project leantegra_importer: Spring application lifecycle JMX bean not found (fork is null). Could not stop application gracefully: org.springframework.boot:type=Admin,name=SpringApplication -> [Help 1]

И приложение не останавливается.

Как сделать корректную остановку? И возможно ли это сделать по Ctrl C?

Share

Тебе может это понравится...