千家信息网

SpringBoot2中环境搭建方法

发表于:2024-11-26 作者:千家信息网编辑
千家信息网最后更新 2024年11月26日,本篇文章为大家展示了SpringBoot2中环境搭建方法,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。导包 org.springframework.boot spring-boot-starter-parent 2.1.6.RELEASE org.springframework.boot spring-boot-starter-web


启动类

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文件加入一个包,就可以实现热启动

   org.springframework.boot            spring-boot-devtools            true        

上述内容就是SpringBoot2中环境搭建方法,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。

0