SpringBoot项目启动后自动打开浏览器

编写一个类,注册为Spring的Bean,然后实现CommandLineRunner接口,重写run()方法即可 package com.example.demo.config;import org.springframework.boot

 

编写一个类,注册为Spring的Bean,然后实现CommandLineRunner接口,重写run()方法即可

 

package com.example.demo.config;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class OpenBrowser implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        System.out.println("应用已经准备就绪 ... 启动浏览器并自动加载指定的页面 ... ");
        try {
            Runtime.getRuntime().exec("cmd   /c   start   http://localhost:8080");//指定自己项目的路径
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/web/1743814106a4511574.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信