springboot实现启动直接访问项目地址

springboot启动直接访问项目地址

方式一

编辑启动类(我的启动类是ApplicationBootstrap) => 进去后找到图中标记处Add按钮

springboot实现启动直接访问项目地址_第1张图片

选中菜单中的 Launch Web Browser => 选择浏览器 => 输入打开网址 => 保存后项目启动

springboot实现启动直接访问项目地址_第2张图片

springboot实现启动直接访问项目地址_第3张图片

启动项目 . . .

方式二

springboot启动直接访问项目地址

该类放置的位置,比springboot 启动类低一级即可,一般我都会创建一个config 文件夹,然后把它们放到一起

package com.hbsc.config; 
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component; 
 
/**
 * @ClassName MyCommandRunner
 * @Author: hanyong
 * @CreateTime: 2019-01-28
 */
@Component
public class MyCommandRunner implements CommandLineRunner {
    @Override
    public void run(String... args) {
        if(true){
            String cmd = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" + " " + "http://localhost:8082";
            Runtime run = Runtime.getRuntime();
            try{
                run.exec(cmd);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}

springboot运行无法访问

学习springBoot 搭建遇到一个问题,在此记录,以便后面自己查看及给遇到相同问题的学习者

创建一个springBoot 项目

springboot实现启动直接访问项目地址_第4张图片

在springBoot 的目录中创建了Controler(控制层),Service(逻辑层),Model(实体类),Dao(数据层)

springboot实现启动直接访问项目地址_第5张图片

项目配置文件

配置了一个mysql数据库连接信息,访问端口号,编码格式,及mybatis配置

springboot实现启动直接访问项目地址_第6张图片

对应的maven中的pom.xml 文件如下:



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.8.RELEASE
         
    
    com.example
    demo
    0.0.1-SNAPSHOT
    springBoot
    Demo project for Spring Boot
    
        1.8
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.1.1
        
        
            mysql
            mysql-connector-java
            5.1.30
        
        
            org.mybatis.generator
            mybatis-generator-core
            1.3.5
        
    
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.7
                
                    
                    src/main/resources/generatorConfig.xml
                    true
                    true
                
                
                    
                        Generate MyBatis Artifacts
                        
                            generate
                        
                    
                
                
                    
                        org.mybatis.generator
                        mybatis-generator-core
                        1.3.7
                    
                
            
        
    

springBoot启动类配置

springboot实现启动直接访问项目地址_第7张图片

运行,访问http://localhost:8080/getUserById,报错

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

查了半天没有发现问题,后来看了编译后文件发现只有mapper的编译文件,xml 文件不存在,在网上查了下原因,在pom.xml 文件中添加


    
        src/main/java
        
            **/*.xml
        
    

重新运行,编译目标文件夹中xml文件生成。访问成功。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

你可能感兴趣的:(springboot实现启动直接访问项目地址)