您好,登錄后才能下訂單哦!
本篇文章為大家展示了SpringBoot2中環境搭建方法,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
導包
<!-- Inherit defaults from Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> </parent> <!-- Add typical dependencies for a web application --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
啟動類
package com.zz;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;/** * 右鍵--》run as application 運行正啟動類的main方法,就可以啟動這個springboot項目。SpringBoot 自帶了 tomcat, 運行這個main方法 的時候,會同時啟動tomcat * @author jiyu * */@SpringBootApplicationpublic class App { public static void main(String[] args) { // TODO Auto-generated method stub SpringApplication.run(App.class, args); }}
右鍵–》run as application 運行正啟動類的main方法,就可以啟動這個springboot項目。SpringBoot 自帶了 tomcat, 運行這個main方法 的時候,會同時啟動tomcat啟動成功的日志 . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.1.6.RELEASE)2019-08-03 21:27:18.453 INFO 16564 --- [ main] com.zz.App : Starting App on DESKTOP-9FM4ENL with PID 16564 (C:\bsea\wp\2019\07\02\SpringBoot2\SpringBootBasic\target\classes started by jiyu in C:\bsea\wp\2019\07\02\SpringBoot2\SpringBootBasic)2019-08-03 21:27:18.460 INFO 16564 --- [ main] com.zz.App : No active profile set, falling back to default profiles: default2019-08-03 21:27:21.273 INFO 16564 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)2019-08-03 21:27:21.342 INFO 16564 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]2019-08-03 21:27:21.343 INFO 16564 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]2019-08-03 21:27:21.496 INFO 16564 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext2019-08-03 21:27:21.496 INFO 16564 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2926 ms2019-08-03 21:27:21.736 INFO 16564 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'2019-08-03 21:27:21.947 INFO 16564 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''2019-08-03 21:27:21.950 INFO 16564 --- [ main] com.zz.App
測試controllerpackage com.zz.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class TestController { @RequestMapping("hello") public String t1(){ return "hello SpringBoot"; }}
測試
添加 熱啟動功能
STS 或者Eclipse 只需要在pom文件加入一個包,就可以實現熱啟動
<!--目的:《可選》引入springboot 熱啟動,每次修改以后,會自動把改動加載,不需要重啟服務了-->
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>
上述內容就是SpringBoot2中環境搭建方法,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。