spring Q&A

  1. spring学习问题记录
    1. spring 资源管理
    2. BeanFactory

spring学习问题记录

spring 资源管理

Q:spring ClassLoader是怎么破坏双亲委派的?

https://www.cnblogs.com/binarylei/p/10312531.html

Q:ResourceLoader的问题?

BeanFactory

Q:BeanFactory 和Application的关系?

Q:spring容器和springMvc容器是一个东西吗? 说说父子容器?

A:https://blog.csdn.net/qfikh/article/details/80507011

Q:简单说说你对spring的理解?

A:?

Q: BeanFactory.getBean() 发生了什么?bean的创建过程?

A:?

Q:spring是怎么处理循环依赖问题?

Q:为什么需要singletonFactories?

A:需要Factories来创bean

Q:spring线程安全问题

A:https://segmentfault.com/a/1190000004255203

Q: beanFactory、factorybean、ObjectFactory的区别你能说说吗

Q: which runs first? beanPostProcess or Initialization Callbacks

A:You can refer to the section 5.8.1 of the Spring docs here. The key point here is that the “postProcessBeforeInitialization” should be read as “postProcessBeforeInitializationCallback” and “postProcessAfterInitialization” should be read as “postProcessAfterInitializationCallback”. So these are pre and post processeors after the before/after initialization callback are run by the Spring container on the bean. This is what is conveyed in the docs of these methods here too.

Q: 启动时候控制台打印的这个是什么意思呢? not eligible for auto-proxying

A:BeanPostProcessor instances and AOP auto-proxying

Classes that implement the BeanPostProcessor interface are special and are treated differently by the container. All BeanPostProcessor instances and beans that they directly reference are instantiated on startup, as part of the special startup phase of the ApplicationContext. Next, all BeanPostProcessor instances are registered in a sorted fashion and applied to all further beans in the container. Because AOP auto-proxying is implemented as a BeanPostProcessor itself, neither BeanPostProcessor instances nor the beans they directly reference are eligible for auto-proxying and, thus, do not have aspects woven into them.

For any such bean, you should see an informational log message: Bean someBean is not eligible for getting processed by all BeanPostProcessor interfaces (for example: not eligible for auto-proxying).

If you have beans wired into your BeanPostProcessor by using autowiring or @Resource (which may fall back to autowiring), Spring might access unexpected beans when searching for type-matching dependency candidates and, therefore, make them ineligible for auto-proxying or other kinds of bean post-processing. For example, if you have a dependency annotated with @Resource where the field or setter name does not directly correspond to the declared name of a bean and no name attribute is used, Spring accesses other beans for matching them by type.

Q: all of beanPostProcess and beanFactoryProcess Extends point :Scope?

A: Also, BeanFactoryPostProcessor instances are scoped per-container.

marking it for lazy initialization will be ignored?

As with BeanPostProcessors , you typically do not want to configure BeanFactoryPostProcessors for lazy initialization. If no other bean references a Bean(Factory)PostProcessor, that post-processor will not get instantiated at all. Thus, marking it for lazy initialization will be ignored, and the Bean(Factory)PostProcessor will be instantiated eagerly even if you set the default-lazy-init attribute to true on the declaration of your `` element.

Q:classLoader 加载效率低? spring有哪些优化 ?

A:Spring IoC 的 Lazy loading 有关, Spring IoC 为了加快初始化速度, 因此大量使用了延时加载技术. 而使用 classloader 不需要执行类中的初始化代码, 可以加快加载速度, 把类的初始化工作留到实际使用到这个类的时候.

Q:有看过官方文档吗 ? Annotation-based Container Configuration 和

Java-based Container Configuration

Using JSR 330 Standard Annotations 这几章的侧重点?(或者谈谈你对注解的理解)

A:

Annotation-based Container Configuration (元信息配置)

🔑关键词: configuration metadata; @Autowired ;@Order;@Primary;@Qulifier;@Resources;BeanPostProcessor

Java-based Container Configuration (java代码的方式实现配置)

@Bean; @Configuration;AnnotationConfigApplicationContext;lite vs full;@Import; @ImportResource;@Condition

Java-based Container Configuration (主要是支持JSR330)

🔑关键词: javax.inject ; @Inject; @Named

Q:Spring的配置文件中

<context:annotation-config />

<context:component-scan base-package=””/>

<mvc:annotation-driven /> 分别有什么不同和联系?

A:那是因为<context:annotation-config />仅能够在已经在已经注册过的bean上面起作用

https://stackoverflow.com/questions/7414794/difference-between-contextannotation-config-and-contextcomponent-scan

Q:Full @Configuration vs “lite” @Bean mode ?

A:在lite @Bean mode模式下, @Bean方法不会被CGLIB代理

That definitely would be problematic: In Spring, instantiated beans have a singleton scope by default.

This is where the magic comes in: All @Configuration classes are subclassed at startup-time with CGLIB.

In the subclass, the child method checks the container first for any cached (scoped) beans before it calls the parent method and creates a new instance.

Q:spring 为什么会使用cglib 、什么时候使用?

A: Spring提供了ProxyFactoryBean创建代理,及利用BeanPostProcessor实现自动创建代理。

Q : spring Xml schema 扩展的了解?

A : https://juejin.im/post/5d06018b518825276a286a3d

Q:LTW是啥?

A: Spring是在运行期利用JDK或CGLib创建代理,我们还可以在类加载期间通过字节码编辑的技术,将切面织入到目标类中,这种织入方式称为LTW(Load Time Weaving)。Spring为LTW的过程提供了细粒度的控制,它支持在单个ClassLoader范围内实施类文件转换,且配置更为简单。

原文链接:https://blog.csdn.net/evergreenfetch/article/details/42002017

将 spring-agent.jar,

spring-aspects.jar,

aspectj-weaver.jar,

aspectj-rt.jar 加入到 classpath 中, 运行期主要发生以下调用 :

LoadTimeWeaverBeanDefinitionParser (spring.jar) // 解析配置
-> AspectJWeavingEnabler (spring.jar) // 开启 aspectj weaving
-> InstrumentationSavingAgent (spring-agent.jar) // 获取 instrumentation
-> InstrumentationLoadTimeWeaver#addTransformer (spring.jar) // 增加 aspectj class transformer 到 instrumentation
-> ClassPreProcessorAgentAdapter#transform (aspectj-weaver.jar) // aspectj 拦截 domain object 装载
-> AnnotationBeanConfigurerAspect#configureBean (spring-aspects.jar) // spring 注入依赖到标注了 @Configurable 的对象中

beanfactory支持aop吗?

BeanFactory or ApplicationContext?

Users are sometimes unsure whether a BeanFactory or an ApplicationContext is best suited for use in a particular situation. A BeanFactory pretty much just instantiates and configures beans. An ApplicationContext also does that, and it provides the supporting infrastructure to enable lots of enterprise-specific features such as transactions and AOP.

为什么

aop是在什么织入的 ?

-bean初始化时

https://juejin.im/entry/5b572405e51d451964625f66

https://www.javadoop.com/post/spring-aop-intro

factorybean beanfactory?

- mvc容器和ioc容器?

√ aop和aspectj?

√ 事件驱动 请求驱动

√ spring bean的实例化?与加载对象的过程?

https://swenfang.github.io/2019/04/22/Spring%E9%9D%A2%E8%AF%95%E9%A2%98/

https://swenfang.github.io/2019/05/12/%E9%9D%A2%E8%AF%95%E6%80%BB%E7%BB%93/%E9%9D%A2%E8%AF%95%E6%80%BB%E7%BB%93/

怎么解决循环依赖问题?

spring listener的初始化时机?

springmvc容器初始化时机?第一次请求为啥比较慢?

springBoot 中的 webApplicationContext 什么时候创建的?

org.springframework.web.servlet.FrameworkServlet#initWebApplicationContext

springBoot的启动流程?

bean为什么会被重复初始化?


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 951488791@qq.com

文章标题:spring Q&A

字数:1.4k

本文作者:zhengyumin

发布时间:2019-12-02, 18:20:38

最后更新:2020-04-29, 17:04:53

原始链接:http://zyumin.github.io/2019/12/02/spring-Q-A/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。