最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

SpringBoot项目启动时自动在浏览器打开

运维笔记admin3浏览0评论

SpringBoot项目启动时自动在浏览器打开

  • 1.创建配置文件
  • 2.直接启动项目

1.创建配置文件

SpringBoot有自带的监听任务,只需实现对应的接口,调用cmd启动浏览器即可

配置文件如下:
package com.qin.mybatispluslearn.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringBootConfiguration;

/**

  • springboot项目启动之后自动启动默认浏览器

  • @author Levi

  • @since 2019/7/4 14:54
    */
    @SpringBootConfiguration
    public class AutoStartProjectInDefaultBrowser implements CommandLineRunner {

    //注入项目的端口号
    @Value("${server.port}")
    private String port;

    /**

    • springboot自带的监听任务
    • @param args
    • @throws Exception
      */
      @Override
      public void run(String… args) throws Exception {
      try {
      Runtime.getRuntime().exec(“cmd /c start
发布评论

评论列表(0)

  1. 暂无评论