springBoot--01--快速入门
笔记源码:https://gitee.com/ytfs-dtx/SpringBoot
1.1 原有Spring优缺点分析
1.1.1 Spring的优点分析
1.1.2 Spring的缺点分析
1.2 SpringBoot的概述
1.2.1 SpringBoot解决上述Spring的缺点
1.2.2 SpringBoot的特点
1.2.3 SpringBoot的核心功能
二、SpringBoot快速入门
2.1 代码实现
2.1.1 创建Maven工程
2.1.2 添加SpringBoot的起步依赖
SpringBoot要求,项目要继承SpringBoot的起步依赖spring-boot-starter-parent
<!-- 所有的SpringBoot工程都必须继承 spring-boot-starter-parent --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.5.RELEASE</version> </parent>
SpringBoot要集成SpringMVC进行Controller的开发,所以项目要导入web的启动依赖
<dependencies> <!-- web功能起步依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--热部署配置--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> </dependencies>
2.1.3 编写SpringBoot引导类
要通过SpringBoot提供的引导类起步SpringBoot才可以进行访问
package xyz.ytfs; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * @author by 雨听风说 * @Classname MySpringBootApplication * @Description TODO(SpringBoot的引导类) * @Date 2020/5/12 1:27 */ //申明该类是一个springboot的启动类 @SpringBootApplication public class MySpringBootApplication { /** * main 是java程序的入口 * @param args */ public static void main(String[] args) { //run方法 表示运行springBoot的引导类 run参数就是springBoot引导类的字节码对象 SpringApplication.run(MySpringBootApplication.class); } }
2.1.4 编写Controller
在引导类MySpringBootApplication同级包或者子级包中创建QuickStartController
/** * @author by 雨听风说 * @Classname QuickController * @Description TODO(快速入门的controller) * @Date 2020/5/12 1:32 */ @Controller public class QuickController { @RequestMapping("quick") @ResponseBody public String quickStart(){ return "hellow world"; } }
2.1.5 测试
执行SpringBoot起步类的主方法,控制台打印日志如下
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.5.RELEASE)
2020-05-12 21:00:02.770 INFO 10340 --- [ restartedMain] xyz.ytfs.MySpringBootApplication : Starting MySpringBootApplication on 一一 with PID 10340 (started by DTX in F:\project folder\winter vacation\springBoot)
2020-05-12 21:00:02.773 INFO 10340 --- [ restartedMain] xyz.ytfs.MySpringBootApplication : No active profile set, falling back to default profiles: default
2020-05-12 21:00:02.918 INFO 10340 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-05-12 21:00:02.918 INFO 10340 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-05-12 21:00:04.144 INFO 10340 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-12 21:00:04.164 INFO 10340 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-12 21:00:04.164 INFO 10340 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-05-12 21:00:04.242 INFO 10340 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-12 21:00:04.242 INFO 10340 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1323 ms
2020-05-12 21:00:04.421 INFO 10340 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-12 21:00:04.587 INFO 10340 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-05-12 21:00:04.624 INFO 10340 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-05-12 21:00:04.627 INFO 10340 --- [ restartedMain] xyz.ytfs.MySpringBootApplication : Started MySpringBootApplication in 2.304 seconds (JVM running for 4.797)
通过日志发现,Tomcat started on port(s): 8080 (http) with context path ”
tomcat已经起步,端口监听8080,web应用的虚拟工程名称为空
打开浏览器访问url地址为:http://localhost:8080/quick