package com.test.web.core.config;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GaiBuSheZhangV1 implements ApplicationContextAware {
private ApplicationContext context;
@PostMapping("/callmedaddy")
public String enjoy() {
ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) context;
ctx.close();
return null;
}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context = applicationContext;
}
}
如何优雅的停止springboot项目
最新推荐文章于 2024-12-03 23:13:20 发布
该Java代码定义了一个名为GaiBuSheZhangV1的@RestController,实现了ApplicationContextAware接口。它包含一个@PostMapping方法,当调用/callmedaddy端点时,会关闭ConfigurableApplicationContext。在setApplicationContext方法中,将应用上下文注入到实例变量。
775

被折叠的 条评论
为什么被折叠?



