springboot實(shí)現(xiàn)啟動(dòng)直接訪問項(xiàng)目地址
springboot啟動(dòng)直接訪問項(xiàng)目地址
方式一
編輯啟動(dòng)類(我的啟動(dòng)類是ApplicationBootstrap) => 進(jìn)去后找到圖中標(biāo)記處Add按鈕
選中菜單中的 Launch Web Browser => 選擇瀏覽器 => 輸入打開網(wǎng)址 => 保存后項(xiàng)目啟動(dòng)
啟動(dòng)項(xiàng)目 . . .
方式二
springboot啟動(dòng)直接訪問項(xiàng)目地址
該類放置的位置,比springboot 啟動(dòng)類低一級(jí)即可,一般我都會(huì)創(chuàng)建一個(gè)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運(yùn)行無法訪問
學(xué)習(xí)springBoot 搭建遇到一個(gè)問題,在此記錄,以便后面自己查看及給遇到相同問題的學(xué)習(xí)者
創(chuàng)建一個(gè)springBoot 項(xiàng)目
在springBoot 的目錄中創(chuàng)建了Controler(控制層),Service(邏輯層),Model(實(shí)體類),Dao(數(shù)據(jù)層)
項(xiàng)目配置文件
配置了一個(gè)mysql數(shù)據(jù)庫連接信息,訪問端口號(hào),編碼格式,及mybatis配置
對(duì)應(yīng)的maven中的pom.xml 文件如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.8.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springBoot</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.30</version> </dependency> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.5</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.7</version> <configuration> <!--配置文件的位置--> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <executions> <execution> <id>Generate MyBatis Artifacts</id> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.7</version> </dependency> </dependencies> </plugin> </plugins> </build> </project>
springBoot啟動(dòng)類配置
運(yùn)行,訪問http://localhost:8080/getUserById,報(bào)錯(cuò)
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
查了半天沒有發(fā)現(xiàn)問題,后來看了編譯后文件發(fā)現(xiàn)只有mapper的編譯文件,xml 文件不存在,在網(wǎng)上查了下原因,在pom.xml 文件中添加
<resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources>
重新運(yùn)行,編譯目標(biāo)文件夾中xml文件生成。訪問成功。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
java數(shù)據(jù)結(jié)構(gòu)關(guān)于棧的實(shí)例應(yīng)用
大家好,本篇文章主要講的是java數(shù)據(jù)結(jié)構(gòu)關(guān)于棧的實(shí)例應(yīng)用,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12Python單元測試_使用裝飾器實(shí)現(xiàn)測試跳過和預(yù)期故障的方法
下面小編就為大家?guī)硪黄狿ython單元測試_使用裝飾器實(shí)現(xiàn)測試跳過和預(yù)期故障的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06教你Spring Cloud保證各個(gè)微服務(wù)之間調(diào)用安全性
在微服務(wù)的架構(gòu)下,系統(tǒng)會(huì)根據(jù)業(yè)務(wù)拆分為多個(gè)服務(wù),各自負(fù)責(zé)單一的職責(zé),在這樣的架構(gòu)下,我們需要確保各api的安全性,今天通過本文給大家分享Spring Cloud中如何保證各個(gè)微服務(wù)之間調(diào)用的安全性,需要的朋友參考下吧2021-08-08JAVA隨機(jī)數(shù)隨機(jī)字母的實(shí)現(xiàn)(微信搶紅包小練習(xí))
這篇文章主要介紹了JAVA隨機(jī)數(shù)隨機(jī)字母的實(shí)現(xiàn)(微信搶紅包小練習(xí)),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04Java基于自定義類加載器實(shí)現(xiàn)熱部署過程解析
這篇文章主要介紹了Java基于自定義類加載器實(shí)現(xiàn)熱部署過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03