二刷spring总结
Kwqin
致力于java分享
展开
-
手把手教你手写Spring框架
手写spring准备工作:新建一个maven工程:架构新建类:package com.spring;public class keweiqinApplicationContext { private Class configClass; public keweiqinApplicationContext(Class configClass) { this.configClass = configClass; } //解析配原创 2021-12-07 16:06:14 · 6181 阅读 · 6 评论 -
Mybatis代理对象和Spring工厂
//AService出现了循环依赖 public Object getEarlyBeanReference(Object bean, String beanName) { Object cacheKey = this.getCacheKey(bean.getClass(), beanName); //beanName aService //判断 this.earlyProxyReferences.put(cacheKey, bea..原创 2021-12-06 23:04:31 · 276 阅读 · 0 评论 -
Spring的循环依赖,循环依赖底层原理、三级缓存解决循环依赖源码分析
什么是循环依赖很简单就是A对象依赖了B对象,B对象依赖了A对象//A依赖了Bclass A{ public B b;}//B依赖了Aclass B{ public A a;}如果不考虑Spring,循环依赖并不是问题,因为对象之间相互依赖是很正常的事情A a=new A();B b=new B();a.b=b;b.a=a;这样A,B就依赖上了spring的循环依赖@Component("aService")public clas原创 2021-12-05 15:04:00 · 666 阅读 · 0 评论 -
续关于@Autowired的加强理解...博客
此条博客需要看关于@Autowired的加强理解,这样才可以连贯下来此路径不应该写死写个注解@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.TYPE)public @interface LubanScan { String value();}主启动类添加注解类上添加此注解这样获取扫描路径输出测试,发现没问题。启动去扫描主类上的注解,找到@LubanScan("com....原创 2021-12-05 14:27:20 · 266 阅读 · 0 评论 -
关于@Autowired的加强理解、ImportBeanDefinitionRegistrar和FactoryBean的经典应用实战
架构UserMapperpublic interface UserMapper { @Select("select 'user'") String selectById(); }UserService@Componentpublic class UserService { @Autowired private UserMapper userMapper; public void test(){ S.原创 2021-12-04 20:44:28 · 1074 阅读 · 2 评论 -
Bean的生命周期之初始化前、初始化后以及模拟Aop
Config@ComponentScan("com.luban")public class config { @Bean public User user(){ return new User(); }}userpublic class User {}userService@Componentpublic class UserService implements InitializingBean { private User user原创 2021-12-03 18:52:02 · 1474 阅读 · 0 评论 -
Bean的生命周期之初始化
config@ComponentScan("com.luban")public class config { @Bean public User user(){ return new User(); }}userpublic class User {}UserService@Componentpublic class UserService implements InitializingBean { private User user原创 2021-12-03 18:29:52 · 505 阅读 · 0 评论 -
Bean生命周期之实例化后
Userpublic class User {}config@ComponentScan("com.luban")public class config { @Bean public User user(){ return new User(); }}UserService@Componentpublic class UserService { private User user; public UserService()原创 2021-12-02 20:03:48 · 261 阅读 · 0 评论 -
Bean的生命周期之实例化和推断构造方法
userpublic class User {}userService@Componentpublic class UserService { private User user; public UserService(User user) { this.user = user; System.out.println(user); System.out.println("一个参数的构造方法"); }}config原创 2021-12-02 16:32:37 · 356 阅读 · 2 评论 -
Bean的生命周期之实例化前
Mainpublic class Main { public static void main(String[] args) { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(config.class); UserService userService = applicationContext.getBean(...原创 2021-12-02 15:55:13 · 317 阅读 · 0 评论 -
Bean的后置处理器有趣的实战
config@ComponentScan("com.luban")public class config {}Luban@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.FIELD)public @interface Luban { String value();}UserService@Componentpublic class UserService { @Luban("lub...原创 2021-12-02 15:18:21 · 140 阅读 · 0 评论 -
Bean的后置处理器
user:@Componentpublic class User { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; }}userService@Componentpublic class UserService { }...原创 2021-12-02 12:41:27 · 618 阅读 · 0 评论 -
可刷新和不可刷新的ApplicationContext详解
public class Main { public static void main(String[] args) { /* ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");*/ AnnotationConfigApplicationContext applicationContext = new.原创 2021-12-02 11:07:21 · 593 阅读 · 0 评论 -
AnnotationConfigApplicationContext
public class Main { public static void main(String[] args) { /* ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");*/ AnnotationConfigApplicationContext applicationContext = new A...原创 2021-12-02 10:17:14 · 6965 阅读 · 0 评论 -
ClassPathXMLApplication和FilePathXmlApplication的区别
ClassPathXMLApplicationpublic class Main { public static void main(String[] args) { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml"); System.out.println(applicationContext.getBean("原创 2021-12-02 10:06:57 · 338 阅读 · 0 评论 -
ApplicationContext与BeanFactory的联系和区别
ClassPathXmlApplicationContextClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");追溯发现其实继承了ApplicationContext继承关系public interface ApplicationContext extends EnvironmentCapable, ListableBeanFa..原创 2021-11-30 12:42:23 · 338 阅读 · 0 评论 -
初始BeanFactory
BeanFactory就是用来生产bean的public class User { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; }}public class Main { public static void main(..原创 2021-11-30 10:58:01 · 100 阅读 · 0 评论 -
单例池的结构和作用
目录xml测试输出;修改,将user1修改成原型bean再次测试单例池xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:.原创 2021-11-30 10:01:58 · 651 阅读 · 0 评论 -
Supplier的使用和定义Bean的方式
为什么能通过user这个名字,拿到注册的bean呢,因为context.registerBean(User.class);相当于注册了一个名为User类首字母小写的beanSupplier的使用:package com.luban;import org.springframework.beans.factory.config.BeanDefinition;import org.springframework.beans.factory.support.AbstractBeanDe...原创 2021-11-30 09:41:18 · 431 阅读 · 0 评论 -
FactoryBean的使用和理解
新建一个person类public class Person {}定义一个FactoryBean实现类public class kwqFactoryBean implements FactoryBean { @Override public Object getObject() throws Exception { Person person = new Person(); return person; } @Overri原创 2021-11-30 09:25:58 · 344 阅读 · 0 评论 -
bean标签、@Bean、@Component、BeanDefinition定义bean
bean标签定义bean所需pom <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.2.10.RELEASE</version>.原创 2021-11-30 08:49:57 · 605 阅读 · 0 评论