當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring Boot快速搭建入门程序
生活随笔
收集整理的這篇文章主要介紹了
Spring Boot快速搭建入门程序
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一、快速搭建入門程序
第一步
新增Spring-Boot-starter-parent依賴【父級項目的web依賴】
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.7.RELEASE</version> </parent>第二步
新增Spring-Boot-starter-web依賴【子項目的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啟動的兩種方法
1.直接運行Main方法
2.使用插件啟動
- 第一步 新增MAVEN插件spring-boot-maven-plugin
- 第二步 MAVEN插件增加<configuration>與<mainClass>,配置啟動主函數(shù)
三、使用application.properties配置項目
properties和yml項目常用的兩種文件配置方式,properties的優(yōu)先級高于yml
- Spring Boot自動生成Resources目錄下的application.properties配置文件
配置格式:key=value - Spring Boot自動生成Resources目錄下的application.yml配置文件
配置格式:key: value(冒號之后由一個空格)
總結
以上是生活随笔為你收集整理的Spring Boot快速搭建入门程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python基础知识-优雅的with a
- 下一篇: SpringBoot从入门到实战只需一篇