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);
}
}
启动调度程序
@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吗?
这篇文章有几个选项。
哭
方法一:
并通过卷曲
curl -X POST localhost:port/shutdownContext方法二:
在控制台中
kill $(cat ./bin/shutdown.pid)