使用maven方式創(chuàng)建springboot項(xiàng)目的方式
使用Spring Initializr創(chuàng)建spring boot項(xiàng)目,因?yàn)橥饩W(wǎng)問題導(dǎo)致很難成功,所以只能使用maven方式,這里介紹下該方式。
壹、創(chuàng)建maven項(xiàng)目
1.創(chuàng)建項(xiàng)目
2.選擇maven類型,jdk版本,空模板
3.填寫項(xiàng)目名稱,本地存儲(chǔ)路徑,group信息,版本等信息
4.項(xiàng)目結(jié)構(gòu)
貳、整改為springboot項(xiàng)目
1.修改pom.xml:繼承spring-boot-starter-parent;自行修改版本
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.12.RELEASE</version> <relativePath/> </parent>
2.修改pom.xml:添加打打包方式
<packaging>jar</packaging>
3.修改pom.xml:添加spring-boot-starter-web依賴包
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
4.修改pom.xml:添加jar包啟動(dòng)入口類
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.te.TestWebApplication</mainClass> </configuration> </plugin> </plugins> </build>
5.完整的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 http://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.3.12.RELEASE</version> <relativePath/> </parent> <groupId>com.te</groupId> <artifactId>test</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.te.TestWebApplication</mainClass> </configuration> </plugin> </plugins> </build> </project>
6.創(chuàng)建Springboot啟動(dòng)類,并添加注解和main方法
package com.te; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class TestWebApplication { public static void main(String[] args) { SpringApplication.run(TestWebApplication.class, args); } }
根據(jù)功能需要:添加其他jar包依賴;創(chuàng)建application.yml、application.properties等文件添加配置項(xiàng)等等
叁、測(cè)試 創(chuàng)建測(cè)試類
package com.te.web; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class TestController { @GetMapping("/test") public String test() { return "hello world"; } }
啟動(dòng)springboot項(xiàng)目,第一次啟動(dòng)類的方式,后面可以使用快捷方式啟動(dòng)
頁面訪問測(cè)試,地址:http://localhost:8080/test
到此這篇關(guān)于使用maven方式創(chuàng)建springboot項(xiàng)目的文章就介紹到這了,更多相關(guān)maven方式創(chuàng)建springboot內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java中Object.equals和String.equals的區(qū)別詳解
這篇文章主要給大家介紹了Java中Object.equals和String.equals的區(qū)別,文中通過一個(gè)小示例讓大家輕松的明白這兩者的區(qū)別,對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。2017-04-04JavaEE SpringMyBatis是什么? 它和Hibernate的區(qū)別及如何配置MyBatis
這篇文章主要介紹了JavaEE Spring MyBatis是什么? 它和Hibernate的區(qū)別有哪些?如何配置MyBatis?本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08Springboot?集成spring?cache緩存的解決方案
這篇文章主要介紹了Springboot?集成spring?cache緩存,使用緩存最關(guān)鍵的一點(diǎn)就是保證緩存與數(shù)據(jù)庫的數(shù)據(jù)一致性,本文給大家介紹最常用的緩存操作模式,對(duì)Springboot?集成spring?cache緩存操作流程感興趣的朋友一起看看吧2022-06-06java前后端使用ajax數(shù)據(jù)交互問題(簡單demo)
這篇文章主要介紹了java前后端使用ajax數(shù)據(jù)交互問題(簡單demo),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。2023-06-06Java實(shí)現(xiàn)AOP功能的封裝與配置的小框架實(shí)例代碼
這篇文章主要介紹了Java實(shí)現(xiàn)AOP功能的封裝與配置的小框架實(shí)例代碼,分享了相關(guān)代碼示例,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-02-02