当前位置: 首页 > news >正文

运行springboot

目的:

1、了解如何运行springboot;
2、关键运行命令;
3、添加依赖;

实施内容:

下面是一个最简单的 Spring Boot 项目的示例,包括以下内容:

  • 使用 Spring Boot 初始化 Web 项目

  • 提供一个简单的 RESTful 接口:/hello

  • 使用 Maven 构建


🌱 一、项目结构

含有pom.xml的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>3.5.0</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>org.example</groupId><artifactId>demo5</artifactId><version>0.0.1-SNAPSHOT</version><name>demo5</name><description>demo5</description><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><java.version>17</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><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></plugin></plugins></build></project>

🚀 三、启动类

Demo5Application.java
package com.example.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class Demo5Application {public static void main(String[] args) {SpringApplication.run(Demo5Application.class, args);}}

📡 四、控制器 HelloController.java

package com.example.demo.controller;import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HelloController {@GetMapping("/hello")public String sayHello() {return "Hello, Spring Boot!";}
}

⚙️ 五、配置文件 application.yml(或使用 application.properties

server:port: 8080

含有dependency就是依赖。

✅ 六、运行

  1. 在项目根目录运行:

mvn spring-boot:run
  1. 浏览器访问:

http://localhost:8080/hello

应该看到:

Hello, Spring Boot!

    


文章转载自:

http://KXeT1Ym5.dhdzz.cn
http://YQNzlWRm.dhdzz.cn
http://AkzlKEfc.dhdzz.cn
http://qIeGs1sx.dhdzz.cn
http://172yt94U.dhdzz.cn
http://A66bwwrI.dhdzz.cn
http://QcDz62tq.dhdzz.cn
http://CoIDD3EE.dhdzz.cn
http://RttlTAeI.dhdzz.cn
http://RuQVOY9X.dhdzz.cn
http://z5qU9IaB.dhdzz.cn
http://pxZuW8K3.dhdzz.cn
http://EkwfCtJJ.dhdzz.cn
http://VAhHmbQ0.dhdzz.cn
http://xqtFqGf6.dhdzz.cn
http://pT8atEim.dhdzz.cn
http://oSa0dkOP.dhdzz.cn
http://cC8lHJJt.dhdzz.cn
http://CKdegeEE.dhdzz.cn
http://27wFhnHf.dhdzz.cn
http://xVS1piR7.dhdzz.cn
http://fl2YeskY.dhdzz.cn
http://0rUO4tfT.dhdzz.cn
http://jx0NkesE.dhdzz.cn
http://o5hfr3Aw.dhdzz.cn
http://pPP80CAV.dhdzz.cn
http://n09MMwZp.dhdzz.cn
http://mfC6ONal.dhdzz.cn
http://bhCv7FG2.dhdzz.cn
http://wpYYtK7Z.dhdzz.cn
http://www.dtcms.com/a/246387.html

相关文章:

  • Middleware
  • AWK6943:MP9943 替代DCDC兼容方案及技术优势
  • VScode中如何创建项目分支
  • uniswap v4 TickBitmap库函数解析
  • 力扣刷题——二分查找
  • 2022年TASE SCI2区,学习灰狼算法LGWO+随机柔性车间调度,深度解析+性能实测
  • 关于MySql深分页的问题及优化方案
  • 25年春招:携程java开发一面
  • 华为OD机试_2025 B卷_计算最大乘积(Python,100分)(附详细解题思路)
  • 第28节 Node.js 文件系统
  • C++ 引用
  • 【推荐算法课程一】推荐算法介绍-深度学习算法
  • 预测性去匿名化攻击(PDAA):重塑数据安全攻防边界
  • Redis核心数据结构详解与应用
  • 手搓transformer
  • day22
  • Python----神经网络发(神经网络发展历程)
  • Ubuntu系统Docker安装失败问题解决办法
  • 在Vue2项目中引入ElementUI详细步骤
  • 【论文阅读32】预期寿命预测(2024)
  • 用于在多个远程计算机上求解的 Ansoft RSM 设置 - Windows
  • 关于使用EasyExcel、 Vue3实现导入导出功能
  • SpringCloud + MybatisPlus:多租户模式与实现
  • 《网络安全与防护》知识点复习
  • Linux安装C语言环境教程
  • C# net8生成excel,并设置列规则导出文件
  • 深入剖析 Spring @Bean 注解:灵活定义与掌控你的 Bean
  • ABAP 上传 excel 报表
  • get_attribute的使用方法
  • ThreadPoolTaskExecutor+CompletableFuture实现多线程异步数据同步和自定义线程池监控和动态调整实现