java框架zu_Spring 简介和启动信息分析

Spring Boot 优点

轻量化

提供 Spring 框架各种默认配置来简化项目配置

内嵌 Web 容器

没有冗余代码生成和XML配置要求

Maven 导包

spring-boot-starter:核心模块,包括了自动配置支持、日志和YAML

spring-boot-starter-test:测试模块,包括JUnit、Hamcrest、Mockito

spring-boot-starter-web:Web模块

一个 Spring Boot 案例应该包括四个部分

主加载类

逻辑实现类

单元测试类

以及资源配置文件。

创建SpringBoot 很简单 ,直接用idea的

d148c09b78a6c3edc269143c351ef531.png选择web工程就行

Spirng Boot 启动debug日志阅读笔记

1、b.l.ClasspathLoggingApplicationListener :先输出使用的各种jar包

2、

afd6814cdac23477d1563858d6d59250.png 一个呆萌的SpringBoot 代表

3、Starting SpringbootlearnApplication on ZhangWenLiang with PID 7664 会启动一个java线程 PID 为7664 ,随机的,这个根据计算机操作系统给的随机调度

4、zu.zwl.SpringbootlearnApplication : The following profiles are active: dev,devdb

打印出所选择的profiles,这里dev是我的开发环境properties和配置环境bean

503fbb160e495cf7aa4cdf2f0f2516d9.png

5、然后跳过了很多个相同的配置文件,很纳闷 不懂

6、ationConfigEmbeddedWebApplicationContext :root of context hierarchy 加载了上下文

7、然后加载了两个默认配置文件

ationConfigEmbeddedWebApplicationContext : Unable to locate MessageSource with name ‘messageSource’:usingdefault[org.springframework.context.support.DelegatingMessageSource@6676f6a0]

MessageSource :i18n用的

applicationEventMulticaster:事件驱动模型 具体干啥的不知道。应该很关键吧

8、t.TomcatEmbeddedServletContainerFactory : None of the document roots [src/main/webapp, public, static] point to a directory and will be ignored.

最开始没有webapp目录,我自己手动建立了,重启试试(过程中歌曲竟然卡了一下)

这里的代码变为.t.TomcatEmbeddedServletContainerFactory : Document root: J:\MAKER\CodeFile\idea\springbootlearn\src\main\webapp ,证明成功了

我添加一个index.html 试试,看刷新后能自动加载不。 是可以的

9、s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8989 (http)

在8989端口启动了

10、o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext

初始化内嵌的webApplicationContext上下文

Root WebApplicationContext: initialization completed in 2520 ms 还是挺快的

11、o.s.b.w.s.ServletContextInitializerBeans : Added existing Servlet initializer bean ‘dispatcherServletRegistration’ 注册web的总跳转dispatcher

org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration.class

12、o.s.b.w.s.ServletContextInitializerBeans : Created Filter initializer for bean ‘characterEncodingFilter‘

org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfiguration.class

初始化 字符编码过滤器

看下源码HttpEncodingAutoConfiguration.class

里面有一个annotation

@ConditionalOnProperty(prefix = “spring.http.encoding”, value = “enabled”, matchIfMissing = true)

一个不可改变量

private final HttpEncodingProperties properties;

应该是有一个properties文件,我找找在哪

692ec40b609b9ec1f8dec59bc16a16e1.png

在这个包下面找到了spring-configuration-metadata.json 文件下有

6b7734aec49fc99c3a02bf04db3d5b79.png

a546b4d3752a7ea9dbba6d91ae36d17d.png

就这样设置了把

13、o.s.b.w.s.ServletContextInitializerBeans :Created Filter initializer for bean ‘hiddenHttpMethodFilter’ 干什么东东的? 它是前端后端数据交互时restFul风格的实现

用的这个org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.class

浏览器 form 表单只支持 GET与 POST 请求,而DELETE、 PUT 等 method 并不支持, Spring3.0 添加了一个过滤器,可以将这些请求转换为标准的 http 方法,使得支持 GET、 POST、 PUT 与DELETE 请求。

实现过程:

前台:

ffc239ad492c45e3f89dc03a18105b27.png

后台:

e19296beaa80eb7ec6982f1009cd85ec.png

需注意:

需要注册org.springframework.web.filter.HiddenHttpMethodFilter监听器来代替最初的org.springframework.web.servlet.DispatcherServlet

看下源码

里面有很多前台的东西

352921930644a87882251746e2313760.png

估计是和前台有关

14、o.s.b.w.s.ServletContextInitializerBeans : Created Filter initializer for bean ‘httpPutFormContentFilter‘; order=-9900, resource=class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.class]

也是监听器 这次和put提交方式有关,需注册,该过滤器只能接受enctype值为application/x-www-form-urlencoded的表单,我累个去,网上对其解释千篇一律,无语,啥时候google了,我先试着读下源码,也是WebMvcAutoConfiguration 。未果,终。

15、o.s.b.w.s.ServletContextInitializerBeans : Created Filter initializer for bean ‘requestContextFilter‘; order=-105, resource=class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class] 这个是内部类

requestContextFilter 是将页面提交的request转发到Controller中

16、然后定义各个filter的拦截路径 / 只拦截 /xxxx , /*拦截所有 /xxx 和/xxx.jsp

267ee4c981cf1c97a4dff6656f78c18e.png

17、然后是初始化过滤器(上面是创建bean)

69cc99f40b6417c970dd5c38a736723d.png

18、s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@306279ee: startup date [Tue Sep 26 23:22:39 CST 2017]; root of context hierarchy

注册总的 controler bean

19、紧接着是映射我们自定义的controller

s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped “{[/first]}” onto public java.util.Mapzzu.zwl.controller.UserController.name1(javax.servlet.ServletResponse)

20、然后是装配好的 映射

b5e1cff7216230007d59c7548fc79e72.png

两个error页面,一个返回json,一个view ,一个/**配置,一个/**/favicon.ico来设置图标

21、o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup

初始化成功了算是

22、ationConfigEmbeddedWebApplicationContext : Unable to locate LifecycleProcessor with name ‘lifecycleProcessor’:usingdefault[org.springframework.context.support.DefaultLifecycleProcessor@5c1bd44c] 一个控制进程的风格,里面一个

private volatile long timeoutPerShutdownPhase = 30000;

23、utoConfigurationReportLoggingInitializer : 日志报告输出

24、

5a598063a46d0079ed7723e44cd4f82e.png

成功启动

25、会自动检测代码变化,然后自动再次初始化

总结:web方面做的比较多,可能后期做着会非常完善吧 ,写篇读书日志然后睡觉喽

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值