使用IDE新建maven项目,如果使用eclipse,则选择jar包方式(不选择war包方式)
必须要引入继承springboot-parent包,它帮我们实现了很多jar的依赖管理(这个在
<dependencies></dependencies>标签外):<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent>pom文件导入springboot-web依赖即可,springboot默认集成spring mvc:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>以上操作完成后,既可编写HelloWorld测试类:
package xyz.welog.controller; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; /** * 这是我的第一个Spring boot */ @RestController @EnableAutoConfiguration public class TestController { @RequestMapping(value = "/hello",method = RequestMethod.GET) public String hello() { return "Hello Spring Boot"; } public static void main(String[] args){ // 运行 SpringApplication.run(TestController.class,args); } }直接运行main方法,有下图结果则成功,浏览器访问:http://localhost:8080/hello
浏览器访问结果:
最基本的Springboot完成
Spring boot 学习之 Hello World
最新推荐文章于 2025-07-07 17:33:26 发布
本文介绍如何使用Eclipse创建Spring Boot项目,并通过一个简单的Hello World示例演示如何搭建基本的Spring Boot应用。文章详细展示了必要的Maven配置及核心代码实现。

1232

被折叠的 条评论
为什么被折叠?



