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

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

目录springboot启动直接访问项目地址方式一方式二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
*/
@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 的目录中创建了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启动访问localhost:8080报错404的解决操作SpringBoot+jsp项目启动出现404的解决方法springboot 项目启动后无日志输出直接结束的解决springboot 项目容器启动后如何自动执行指定方法springboot项目突然启动缓慢的解决SpringBoot 在项目启动之后执行自定义方法的两种方式小结springboot项目启动,但是访问报404错误的问题


比丘资源网 » springboot实现启动直接访问项目地址

发表回复

提供最优质的资源集合

立即查看 了解详情