Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/util/ApplicationContextProvider.java
@@ -1,36 +1,17 @@
package com.vci.starter.web.util;
import com.vci.starter.web.annotation.controller.VciUnCheckRight;
import com.vci.starter.web.annotation.log.VciUnLog;
import com.vci.starter.web.autoconfigure.AppAutoConfigure;
import com.vci.starter.web.pagemodel.BaseResult;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * spring的上下文工具,
 * 注意springmvc中的controller不应该在这里获取,因为springmvc只应该被前端调用
 * 没有使用springboot的main函数里设置并获取是因为可能会让多个服务合并到一起启动
 * @author weidy
 * @date 2019/10/31 9:02 AM
 * @author dangsn
 * @date 2024/12/3
 */
@RestController
@RequestMapping("/application")
@Component
public class ApplicationContextProvider implements ApplicationContextAware {
    /**
     * 服务的配置
     */
    @Autowired
    private AppAutoConfigure appAutoConfigure;
    /**
     * 应用的上下文
@@ -39,12 +20,12 @@
    /**
     * 设置应用的上下文
     * @param applicationContext 上下文
     * @param context 上下文
     * @throws BeansException 出现错误时需要抛出异常给spring容器
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationContextProvider.applicationContext = applicationContext;
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        applicationContext = context;
    }
    /**
@@ -75,33 +56,4 @@
    public static <T> T getBean(Class<T> c) throws BeansException{
        return applicationContext.getBean(c);
    }
    /**
     * 关机
     * @return 执行完成
     */
    @PostMapping("/shutDownContext")
    @VciUnLog
    @VciUnCheckRight
    public BaseResult shutDownContext(String privateKey){
        if( appAutoConfigure.getPrivateTokenKey().equalsIgnoreCase(privateKey)) {
            ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) applicationContext;
            ctx.close();
            return BaseResult.success("关闭服务成功");
        }else{
            return BaseResult.fail("您没有权限关闭服务");
        }
    }
    /**
     * 检查是否完成
     * @return 调用就说明成功了
     */
    @PostMapping("/checkOnline")
    @VciUnLog
    @VciUnCheckRight
    public BaseResult checkOnline(){
        return BaseResult.success("启动完成");
    }
}