|
@@ -0,0 +1,43 @@
|
|
|
+package thyyxxk.webserver.controller;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+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;
|
|
|
+import thyyxxk.webserver.config.auth.PassToken;
|
|
|
+import thyyxxk.webserver.config.exception.ExceptionEnum;
|
|
|
+import thyyxxk.webserver.entity.ResultVo;
|
|
|
+import thyyxxk.webserver.utils.ResultVoUtil;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+public class ShutDownController implements ApplicationContextAware {
|
|
|
+
|
|
|
+ private ApplicationContext context;
|
|
|
+
|
|
|
+ @PostMapping("/shutDownContext")
|
|
|
+ @PassToken
|
|
|
+ public ResultVo<String> shutDownContext(HttpServletRequest request) {
|
|
|
+ log.info("请求来源:{}", request.getRemoteAddr());
|
|
|
+ String localhost = "0:0:0:0:0:0:0:1";
|
|
|
+ if (localhost.equals(request.getRemoteAddr())) {
|
|
|
+ log.info("执行关机");
|
|
|
+ ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) context;
|
|
|
+ ctx.close();
|
|
|
+ } else {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "你没有权限访问");
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(ExceptionEnum.SUCCESS, "关闭");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setApplicationContext(@NotNull ApplicationContext applicationContext) throws BeansException {
|
|
|
+ context = applicationContext;
|
|
|
+ }
|
|
|
+}
|