第一个SpringBoot应用程序
2021/7/6 17:39:27
本文主要是介绍第一个SpringBoot应用程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1. 创建POM
创建一个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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ttpfx</groupId> <artifactId>sb01-helloworld</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.2</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
2. 创建主程序
package com.ttpfx.boot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class MainApplication { public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); } }
3. 创建HelloController
package com.ttpfx.boot.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @RequestMapping("/hello") public String handle() { return "Hello SpringBoot!"; } }
4. 运行程序
4.1 在IDEA中运行MainApplication:
4.2 浏览器访问http://localhost:8080/hello:
5. 打成jar包
5.1 pom.xml中增加打包配置:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
5.2 IDEA中打包:
5.3 运行jar包
5.4 浏览器访问http://localhost:8080/hello:
6. 配置文件
6.1 src/main/resources/下增加application.properties配置文件:
server.port=8888
6.2 运行MainApplication,浏览器访问http://localhost:8888/hello:
更多配置参考:https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties
这篇关于第一个SpringBoot应用程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?