如何优雅的停止springboot项目

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;
    }
}

猜你喜欢

转载自blog.csdn.net/csdn_avatar_2019/article/details/128922543