千家信息网

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

发表于:2024-10-01 作者:千家信息网编辑
千家信息网最后更新 2024年10月01日,这篇文章主要为大家展示了"springboot如何实现启动直接访问项目地址",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"springboot如何实现启动直
千家信息网最后更新 2024年10月01日springboot如何实现启动直接访问项目地址

这篇文章主要为大家展示了"springboot如何实现启动直接访问项目地址",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"springboot如何实现启动直接访问项目地址"这篇文章吧。

springboot启动直接访问项目地址

方式一

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

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

启动项目 . . .

方式二

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 */@Componentpublic 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 的目录中创建了Controler(控制层),Service(逻辑层),Model(实体类),Dao(数据层)

项目配置文件

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

对应的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启动类配置

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

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

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

            src/main/java                    **/*.xml            

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

以上是"springboot如何实现启动直接访问项目地址"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

0