spring-boot v3.0.1文档学习笔记 项目基础搭建 1
1、使用cli工具创建项目
spring-boot-cli v3.0.1 下载 repo.spring.io
根据文件时间,下载最新版full.jar,bin.zip备用
执行以下指令,自动将使用gradle模板代码生成到dev文件夹中。
1 | java -jar spring-boot-cli-3.1.0-20230127.015203-8-full.jar init dev |
2、使用mvn创建项目
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 4 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 <groupId>com.example</groupId> 7 <artifactId>myproject</artifactId> 8 <version>0.0.1-SNAPSHOT</version> 9 <parent> 10 <groupId>org.springframework.boot</groupId> 11 <artifactId>spring-boot-starter-parent</artifactId> 12 <version>3.0.1-SNAPSHOT</version> 13 </parent> 14 <!-- 将在此添加其他行... --> 15 <!-- ((只有当你使用 milestone 或 snapshot 版本时,你才需要这个。)) --> 16 <repositories> 17 <repository> 18 <id>spring-snapshots</id> 19 <url>https://repo.spring.io/snapshot</url> 20 <snapshots> 21 <enabled>true</enabled> 22 </snapshots> 23 </repository> 24 <repository> 25 <id>spring-milestones</id> 26 <url>https://repo.spring.io/milestone</url> 27 </repository> 28 </repositories> 29 <pluginRepositories> 30 <pluginRepository> 31 <id>spring-snapshots</id> 32 <url>https://repo.spring.io/snapshot</url> 33 </pluginRepository> 34 <pluginRepository> 35 <id>spring-milestones</id> 36 <url>https://repo.spring.io/milestone</url> 37 </pluginRepository> 38 </pluginRepositories> 39 </project>
将以上xml内容写入pom.xml文件,使用mvn package 尝试构建,验证文件正确性。
pom的详细资料 史上最全的 pom.xml 文件详解_
3、查看项目依赖
使用以下命令查看项目依赖,首次执行时会下载很对jar包,下载结束后会显示分析结果。
mvn dependency:tree
4、mv启动项目
mvn spring-boot:run
命令启动有前提条件,需要项目编译成功并输出class文件。
提示需要配置mainClass,或者找不到MyApplication,都是因为class文件没有输出。mvn compile不能输出class文件,使用idea buid project功能编译输出。
5、项目目录结构
会根据启动类自动扫描所有子包,目录结构不正确会影响扫描结果。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!