导包
<!-- 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
*
*/
@SpringBootApplication
public 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: default
2019-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 WebApplicationContext
2019-08-03 21:27:21.496 INFO 16564 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2926 ms
2019-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
测试controller
package com.zz.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public 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>