GithubHelp home page GithubHelp logo

blog's People

Contributors

zxy16305 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

cl2014620

blog's Issues

Javascript/TypeScript/thymeleaf.....

Javascript

AMD(Asynchronous Module Definition)规范

存在两种规范,CommonJS和AMD。
对于AMD,采用异步方式加载模块,模块的加载不影响后面语句的运行。
eg. require([module],callback)

Tool Mark

有关于一些工具的便捷使用技巧

学自各位大佬 👍

spring源码阅读笔记

①--bean的搜索流程 #1

ClassPathXmlApplicationContext 、WebApplicationContext

  • 在置入基础的环境(applicationContext)后 , 注入xml的位置,并解析其中的占位表达式。

  • refresh() : 加载或者刷新配置的持久层表示

    (以下内容基本为源码的注解翻译 😂 见笑见笑)

    • 准备context

    • 获取bean factory(DefaultListableBeanFactory)

    • 准备这个context要使用的bean factory

      • 设置bean factory的class loader,一般为thread class loader
      • 指定bean中表达式的解析方式, 默认为spel表达式
      • Configure the bean factory with context callbacks.(不懂)
      • BeanFactory interface not registered as resolvable type in a plain factory.
        // MessageSource registered (and found for autowiring) as a bean.(不懂 😂 )
      • 创建一个bean factory 配置时调用的 BeanPostProcessor(是个Hook,用来识别listener的bean)

      bean的存储方式(以DefaultListableBeanFactory为例), 存在这四个容器中:

      • Map<String,Object> singletonObjects ;
      • Map<String,ObjectFactory<?>> singletonFactories ;
      • Map<String,Object> earlySingletonObjects ;
      • Set registeredSingletons ;
    • 允许bean factory的后期处理(然而这一步什么也没做)

    • 在上下文中调用注册为bean的factory processors(2018/1/22)

    在这一步或者这一步之前已经完成了对bean注解的搜索(在beanFactory也就是后面的registry里,看到了所有的bean)

    • 注册能拦截bean创建的bean处理器(InstantiationAwareBeanPostProcessor、DestructionAwareBeanPostProcessor)

    意思是在监听bean的行为,触发一些方法

    • 初始化context消息源

    好像是国际化?
    就结果来看,只加了一个messageSource的bean

    • 初始化context事件广播

    就结果来看,只加了一个叫applicationEvenMulticaster的bean,默认为SimpleApplicationEventMulticaster。

    • 初始化子类指定context的特殊bean

    对于AbstractRefreshableWebApplicationContext而言,只是初始化了themeSource

    • 检查监听bean并初始化

    初始化..就是把这个bean的name加入了一个set中

    • 实例化剩下(非懒加载)的所有单实例

    也就是之前看到的controller的实例化 :在AbstractBeanFactory.doGetBean()里面

    • 发布相应的事件


小记

  • bean(非懒加载)的实例化是在finishBeanFactoryInitialization(beanFactory);这一步完成的
  • 所有bean扫描储存在DefaultListableBeanFactory.beanDefinitionNames


疑问

  • ApplicationContext的结构问题--经常看到context.getParent() 这一句--及 instanceof 他的一个bean(ThemeSource) 是什么鬼
  • 父接口 可以 instanceof 子接口吗?

spring源码阅读笔记②--常用接口

记录一些常用到的接口的功能


  • BeanPostProcessor : 用来做一些bean的初始化/销毁时调用的函数(hook)
  • PriorityOrdered :
    下面这两个接口影响到添加BeanPostProcessor 的标志位
  • InstantiationAwareBeanPostProcessor : 可在bean实例化前/后调用的方法
  • DestructionAwareBeanPostProcessor:可在bean销毁前调用方法

以上所述方法都是接口中的方法 😂

  • SingletonBeanRegistry:公用的单实例注册接口
  • ThemeSource : 用来管理Theme
  • Theme : 用来管理MessageSource
  • ApplicationEventMulticaster : 用来管理ApplicationListener和他的事件
  • Aware :

Blog 项目所遇到部分问题

  1. JPA插入时提示值不能为空的问题
    在打开 spring boot 中的 application.properties 中加入配置: spring.jpa.show-sql=true,查看sql,果然插入了null值,使得数据库配置的默认值失效了。
    随后通过搜索引擎得知,在实体类上加入配置,@DynamicInsert、@DynamicUpdate ,使其忽略掉空值的注入即可

MYSQL笔记

1.mysql在windows环境下的大小写配置
找到my.ini ,加入
lower_case_table_names = 0
(如果此时启动mysql服务报错了,那么就改成2,这是由于mysql的版本造成的)
即为大小写敏感,1为不敏感

springboot配置服务器符合CORS规范

https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/htmlsingle/#boot-features-cors

按照这样配一下就好了 :滑稽:
前台本来是按照教程使用xmlHttpResquest,有点麻烦。
后来经过测试,jquery的ajax就可以使用(使用的版本是jquery-3.3.1)。

进一步验证(刚才是在本地的另一个端口的服务器前段进行的验证),在随便一个网页上(非https),插入jquery的js(document.write("<script language='javascript' src='https://code.jquery.com/jquery-3.3.1.min.js'></script>");),再同样运行jquery的ajax请求本地服务器,得到了同样的结果

spring源码阅读笔记④--RequestDispatcherServlet

前瞻

spring同一般的tomcat的servlet程序,只在web.xml处多配了 ContextLoaderListener和RequestDispatcherServlet两个类,就完成了servlet的拓展。看过了ComtextLoaderListener后(一知半解),再来看看ResquestDispatcherServlet。


在web.xml把他配成了一个servlet,并映射到 “/”路径上(一般情况下),这样任何请求都会到这个servlet里面。
观察其重写方法( init() , service(req,resp) , destroy() )的位置,

  • 重写 init()方法在 HttpServletBean 里面,
  • 重写 service() 方法在 FrameworkServlet 里面(同时也重写了do**方法)
  • 重写 destory() 方法在 FrameworkServlet 里面

流程简介

image

这个流程把主要的方法(有注释的方法 😂)列出来了,第二步看上去很奇怪是因为,HttpServlet里没有定义Patch的method。

spring源码阅读笔记⑤--注解记录--持续更新

bean factory 的初始化

    *
  1. BeanNameAware's {@code setBeanName} *
  2. BeanClassLoaderAware's {@code setBeanClassLoader} *
  3. BeanFactoryAware's {@code setBeanFactory} *
  4. EnvironmentAware's {@code setEnvironment} *
  5. EmbeddedValueResolverAware's {@code setEmbeddedValueResolver} *
  6. ResourceLoaderAware's {@code setResourceLoader} * (only applicable when running in an application context) *
  7. ApplicationEventPublisherAware's {@code setApplicationEventPublisher} * (only applicable when running in an application context) *
  8. MessageSourceAware's {@code setMessageSource} * (only applicable when running in an application context) *
  9. ApplicationContextAware's {@code setApplicationContext} * (only applicable when running in an application context) *
  10. ServletContextAware's {@code setServletContext} * (only applicable when running in a web application context) *
  11. {@code postProcessBeforeInitialization} methods of BeanPostProcessors *
  12. InitializingBean's {@code afterPropertiesSet} *
  13. a custom init-method definition *
  14. {@code postProcessAfterInitialization} methods of BeanPostProcessors *

spring源码阅读笔记③

可以研究的细节

  • getBeanNamesForType 的具体实现方式(先看作一个整体,方便阅读源码逻辑)
  • RootBeanDefinition 这个类在bean创建的时候被用到

spring data JPA 笔记

基于 1.11.10.RELEASE (spring boot 1.5.10.RELEASE 所用的版本)


由于上次看文档没有看到复杂查询, 这次再仔细看一遍


书签

maven笔记

maven发布到**仓库笔记

先搬几个链接
https://my.oschina.net/songxinqiang/blog/313226?p=1&temp=1517196380855#blog-comments-list
https://www.xncoding.com/2018/01/27/tool/maven-central.html

发布这东西果然异常麻烦
先是照着第二位老哥的教程走了一遍没走通。后来以为*.pom的配置出了问题,便继承了第一位老哥的提供的pom。顺便登录查看下自己的仓库,才发现密码被改了??? 可能是太简单的缘故:joy: 在改回密码后Bianc便顺利提交了...

发布的命令是

mvn clean deploy -P oss

其中oos表示*.pom中的 serverId

Java-other

Apache POI

简单地东西就跳过了,在官方的demo上都找得到
1.poi-excel插入图片的坑

excel官方提供了两种,HSSFWorkbook和XSSFWorkbook
这里这个只试出了HSSFWorkbook的简单操作(注解和demo少得可怜。。)

    Workbook wb = new HSSFWorkbook();
    Sheet sheet = wb.createSheet("new");
    //画笔,一个sheet创建一个就行了
    Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch();
    int pictureIndex1 = wb.addPicture(data1, Workbook.PICTURE_TYPE_JPEG);
    //这个初始化参数决定插入的图片的参数
    ClientAnchor xssfClientAnchor1 = new HSSFClientAnchor(0,0,1023,127,(short)0,0,(short)0,0);
    drawingPatriarch.createPicture(xssfClientAnchor1,pictureIndex1);
    //保存
    wb.write(outputStream);

这里讲一下这个构造函数 new HSSFClientAnchor(int dx1, int dy1, int dx2, int dy2, short col1, int row1, short col2, int row2)

 * @param dx1  the x coordinate within the first cell.
 * @param dy1  the y coordinate within the first cell.
 * @param dx2  the x coordinate within the second cell.
 * @param dy2  the y coordinate within the second cell.
 * @param col1 the column (0 based) of the first cell.
 * @param row1 the row (0 based) of the first cell.
 * @param col2 the column (0 based) of the second cell.
 * @param row2 the row (0 based) of the second cell.

其中dx的取值是0-1023,dy的取值是0-255.
他会把下一格分成这么多份,然后去规范图片的大小
(但同时会失去拉伸性能)

Spring Security 文档阅读笔记

第一页献给生词

先看的是目录(怎么有这么长的目录)

LDAP DSL CAS JAAS CSRF

(然后发现我之前看的连基础内容都还没看完 😂)

重要的配置项

HttpSecurity 里面一堆配置方法(注释非常齐全)【重头配置】


记录文档的页码(书签)

5.8.2 GlobalMethodSecurityConfiguration--2018-2-2--
9.4.1 ExceptionTranslationFilter--2018-2-6--

springboot笔记

再开个坑(见鬼了)
springboot的源码,从SpringApplication的注释开始读起

多以以下的的内容多数可在源码的注释里找到


SpringApplicaiton在默认情况下要干的事情

  1. 创建一个ApplicationContext
  2. 注册一个CommandLinePropertySource,来读取命令行参数,使其为spring的properties
  3. 加载所有单实例(bean)
  4. 触发所有 CommandLineRunner 的bean

SpringApplication的资源读取器

  1. 类的加载(Class):AnnotatedBeanDefinitionReader
  2. 资源加载(Resource):XmlBeanDefinitionReader、GroovyBeanDefinitionReader
  3. 包加载(Package):ClassPathBeanDefinitionScanner
  4. 字符加载(CharSequence):CharSequence

相比较其他spring的注释,boot的注释真的是简单明了啊 😂


收回之前的话 方法里依然得读死:joy:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.