温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SpringBoot2中环境搭建方法

发布时间:2021-09-29 17:55:57 来源:亿速云 阅读:126 作者:柒染 栏目:大数据

本篇文章为大家展示了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中环境搭建方法,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI