當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring Boot快速搭建入门程序
生活随笔
收集整理的這篇文章主要介紹了
Spring Boot快速搭建入门程序
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一、快速搭建入門程序
第一步
新增Spring-Boot-starter-parent依賴【父級(jí)項(xiàng)目的web依賴】
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.7.RELEASE</version> </parent>第二步
新增Spring-Boot-starter-web依賴【子項(xiàng)目的web依賴】
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency> </dependencies>第三步
使用@SpringBootApplication注解并創(chuàng)建主程序類
@SpringBootApplication public class HelloApplication {public static void main(String[] args){SpringApplication.run(HelloApplication.class);} }第四步
創(chuàng)建Controller HelloWorld訪問程序
@RestController public class HelloWorldController {@RequestMapping("/hello")public String hello(){return "This is my first SpringBoot Application";} }二、SpringBoot啟動(dòng)的兩種方法
1.直接運(yùn)行Main方法
2.使用插件啟動(dòng)
- 第一步 新增MAVEN插件spring-boot-maven-plugin
- 第二步 MAVEN插件增加<configuration>與<mainClass>,配置啟動(dòng)主函數(shù)
三、使用application.properties配置項(xiàng)目
properties和yml項(xiàng)目常用的兩種文件配置方式,properties的優(yōu)先級(jí)高于yml
- Spring Boot自動(dòng)生成Resources目錄下的application.properties配置文件
配置格式:key=value - Spring Boot自動(dòng)生成Resources目錄下的application.yml配置文件
配置格式:key: value(冒號(hào)之后由一個(gè)空格)
總結(jié)
以上是生活随笔為你收集整理的Spring Boot快速搭建入门程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python基础知识-优雅的with a
- 下一篇: SpringBoot从入门到实战只需一篇