如何实现Spring Boot启动/重启页面

时间:2016-11-16 10:11:13

标签: java spring spring-mvc spring-boot

当我启动Spring Boot应用程序时,需要时间来加载所有需要的工件,这是完全可以接受的。用户需要等待2分钟。

是否可以实现起始页面“你好!我们正在开始......等一下”并在完成后重新加载到主页面?我正在使用Spring Boot。

2 个答案:

答案 0 :(得分:2)

您可以尝试this solution

Tomcat在所有Bean初始化时启动,因此您可以监视此启动并在某些页面上显示。

答案 1 :(得分:1)

也许您可以将HTTP服务器代理到您的服务器。如果您的服务器关闭,您可以显示一个简单的HTML页面,其中包含您建议的消息。

ProxyPass        / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

ErrorDocument 404 /loading.html

在此页面中,对您的真实页面执行AJAX调用。例如(为方便起见,我使用了jQuery,但你也可以使用vanilla javascript或其他库):

function pollPage(){
    $.get("http://localhost:8080/realpage", function(data) { //when page is loaded, replace content of current page
        var replacePage = document.open("text/html", "replace");
        replacePage.write(data);
        replacePage.close();
    }, function(){
         setTimeout(pollPage, 10000); //If page is still inaccesible try again in 10 seconds
    });
}

这将用您的真实页面替换整个初始页面。

相关问题