有时候服务器不方便重启,但是项目又需要更新,所以可以采取如下方法来重新加载Spring项目的Context
//注入ConfigurableWebApplicationContext
@Resource
ConfigurableWebApplicationContext wac;
在方法中调用
wac.refresh();
完整代码
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.ConfigurableWebApplicationContext;
@Controller
@RequestMapping("/test")
public class TestController {
@Resource
ConfigurableWebApplicationContext wac;
@RequestMapping("reload")
public void url(){
wac.refresh();
}
}