spring
一笑而过者也
爱好java,分布式开发
展开
-
Spring后置处理器
1. BeanPostProcessorpublic interface BeanPostProcessor { @Nullable default Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; } @Nullabl...原创 2020-03-15 21:44:28 · 515 阅读 · 0 评论 -
spring中七种事务传播属性
/* * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * ...原创 2018-08-06 22:33:13 · 526 阅读 · 0 评论 -
@ComponentScan 详解
@ComponentScan 的作用就是根据定义的扫描路径,把符合扫描规则的类装配到spring容器中,注解定义如下。@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.TYPE})@Documented@Repeatable(ComponentScans.class)public @interface Compon...原创 2018-09-18 23:13:28 · 56538 阅读 · 1 评论 -
spring事件ApplicationEvent/ApplicationListener/@EventListener注解
spring自带事件功能,继承自jdk中的事件,事件其实是用的观察者设计模式,spring容器在启动时,把所有的lisenter存起来,当发布事件时,再循环lisenter集合,然后调用。写一个事件发布者,MyEvent是我自己定的一个实体类,代表事件的主体,注入ApplicationContext,ApplicationContext继承了ApplicationEventPublisher,...原创 2018-09-25 21:49:11 · 2665 阅读 · 0 评论 -
@Scope @Lazy @Bean注解注解
先看下面代码:package com.xhx.spring.config;import com.xhx.spring.domain.Person;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.config.Configurab...原创 2018-09-28 21:45:19 · 977 阅读 · 0 评论 -
spring @Primary @Autowired @Qualifier注解
当spring中管理两个类型一样的bean时,再进行注入时会报错:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.xhx.spring.Spring5AutowiredQualifierApplicationTests': Unsatisf...原创 2018-09-28 21:59:26 · 944 阅读 · 0 评论 -
spring @Autowired @Resource注解
@Autowired:是spring的注解,可以与@Qualifier、@Primary结合使用,可以选择required属性,实现按类型注入、名称注入或者是找不到合适的就不注入。@Resource 是javax JSR250,首先按name注入,然后按照类型注入,否则就会报错,相对来说没有@Autowired功能强大...原创 2018-09-28 22:06:08 · 173 阅读 · 0 评论 -
spring BeanPostProcessor后置处理器
这个接口有两个方法:public interface BeanPostProcessor { @Nullable default Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; } @Nullable defa...原创 2018-09-29 12:00:25 · 306 阅读 · 0 评论 -
cglib动态代理
cglib实现的代理为被代理类的子类,当调用代理类方法的时候,会根据设置的回调类,执行里面的拦截的方法。被代理的类:package com.xhx.java;public class Hello { public void say(){ System.out.println("hello world"); }}首先创建代理类:用Enhancer...原创 2018-09-29 17:09:03 · 157 阅读 · 0 评论