Maven构建SpringBoot项目

来源:互联网 发布:店面招牌设计软件 编辑:程序博客网 时间:2024/05/18 03:06

注意点:

1、生成的应用位置应该放在groupId的文件夹下面

目的:

构建一个Spring Boot项目,并实现一个简单的Http请求处理了解Spring Boot项目创建,运行过程,项目结构,简单、开发快速的特性

Spring Boot 的优点:

1,开发者快速入门2,开箱即用(自带各种默认配置,简化项目配置项)3,无冗余代码生成和XML配置文件

创建SpringBoot项目

访问:http://start.spring.io/ , 通过SPRING INITIALIZR工具生成基础项目

SpringBoot项目生成


查看项目

使用idea,导入Maven项目,项目结构如下:

SpringBoot项目结构


引入Web模块

新建工程的pom.xml,引入了2个依赖模块 
spring-boot-starter:核心模块,包括自动配置支持、日志和YAML 
spring-boot-starter-test:测试模块,包括JUnit、Hamcrest、Mockito

需要引入Web模块 : pring-boot-starter-web

<dependencies>   <!-- 核心模块,包括自动配置支持、日志和YAML -->   <dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter</artifactId>   </dependency>   <!-- 测试模块,包括JUnit、Hamcrest、Mockito -->   <dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter-test</artifactId>      <scope>test</scope>   </dependency>   <!-- 引入Web模块 -->   <dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter-web</artifactId>   </dependency></dependencies>


添加HelloWord服务

添加HelloWord服务

启动主程序

启动主程序

打开浏览器访问http://localhost:8080/hello,页面输出Hello World

HelloWorld

Web项目创建完成

原创粉丝点击