
Spring
wangyongxun1983
这个作者很懒,什么都没留下…
展开
-
22--IOC总结
https://github.com/DocsHome/spring-docs/tree/master/pages/core 【Spring API】原创 2020-10-10 03:17:47 · 83 阅读 · 0 评论 -
21--自动装配-@Profile环境搭建和环境的注册
Profile Spring为我们提供的可以根据当前环境,动态的激活和切换一系列组件的功能比如: 开发换件、测试环境、生产环境数据源(A/B/C) 指定组件在那个环境的情况下才被注册的父容器中,如果不指定任何环境下都能注册加了环境标识的环境只有这个环境激活才能注册到容器中import org.springframework.beans.factory.annotation.Value;import org.springframework.context.Embedd...原创 2020-10-10 02:44:21 · 136 阅读 · 0 评论 -
19--自动装配-方法、构造器位置的自动装配.
原创 2020-10-10 01:34:20 · 148 阅读 · 1 评论 -
18--自动装配-@Resource&@Inject
Spring还支持使用@Resource(JSR250)和@Inject(JSR330)[java规范的注解]@Resource:可以和@Autowired一样实现自动装配,默认是按照组件的名称进行装配 没有支持@Primary功能,没有支持@Autowired(required=false)功能@Inject:需要导入javax.inject的包,和@Autowired功能一样,但是没有required=false功能...原创 2020-10-10 01:16:37 · 94 阅读 · 0 评论 -
17--自动装配-@Autowired&@Qualifier&@Primary
自动装配spring利用依赖注入(DI),完成对IOC容器中各个组件的依赖关系@Autowired:自动注入默认优先按照类型去容器中找对应的组件 如果在容器中找到多个组件,再将属性名称作为组件的id去容器中查找,或通过@Qualifier("xxx")组件指定组件的id,而不是使用属性的名称 自动装配默认一定要将属性赋值好,没有就会报错。也可以设置@Autowired(required=false) @Primary:让Spring自动装配的时候,默认使用首选的bean,也可以继续使用@Q原创 2020-10-10 01:04:55 · 120 阅读 · 0 评论 -
16--指定多个注解可以重复使用
@Repeatable(Xxxxx.class)原创 2020-10-09 23:53:01 · 437 阅读 · 0 评论 -
15--属性赋值-@Value赋值和@PropertySource加载外部配置文件
使用@Value赋值基本数据类型 可以写:SpringEL表达式#{} 也可以写${}:取出配置文件【properties】的值(运行在环境变量里面的值)import org.springframework.beans.factory.annotation.Value;public class PersonBean { /** * 使用@Value赋值 * 1、基本数据类型 * 2、可以写:SpringEL表达式#{} * 3、也可以写${}:取出配置文件【proper原创 2020-10-09 23:45:34 · 173 阅读 · 0 评论 -
14--生命周期-BeanPostProcessor在Spring底层的使用.
Spirng底层对BeanPostProcessor 无论是赋值,注入其他,如@Autowired,生命周期注解功能等等原创 2020-10-09 23:21:35 · 95 阅读 · 0 评论 -
13--生命周期-BeanPostProcessor-后置处理器
BeanPostProcessor(接口):bean的后置处理器在bean初始化前后进行一些处理工作【1】、BeanPostProcessor#postProcessBeforeInitialization 在初始化之前Apply this BeanPostProcessor to the given new bean instance beforeany bean initialization callbacks (like InitializingBean's {@code afterPr原创 2020-10-09 22:36:06 · 181 阅读 · 0 评论 -
12--生命周期-@PostConstruct&@PreDestroy
@PostConstruct:在bean创建完成并且属性赋值完成;来执行初始化方法@PreDestroy:在容器销毁bean之前通知我们进行清理工作import javax.annotation.PostConstruct;import javax.annotation.PreDestroy;import org.springframework.stereotype.Component;@Componentpublic class Dog { public Dog() {..原创 2020-10-09 20:32:40 · 224 阅读 · 0 评论 -
11--生命周期-InitializingBean和DisposableBean
【1】通过Bean实现InitializingBean这个接口(定义初始化逻辑)Invoked by a BeanFactory after it has set all bean properties supplied由BeanFactoryBean提供的所有属性。【2】通过DisposableBean这个接口(销毁bean) 由BeanFactory在单例销毁时调用。import org.springframework.context.annotation.Bean;import ..原创 2020-10-09 20:21:46 · 115 阅读 · 0 评论 -
10--生命周期-@Bean指定初始化和销毁方法
/*** bean的生命周期:* bean的创建--->>初始化--->>销毁的过程* 容器管理bean的生命周期* 我们可以定义初始化和销毁的方法,容器在bean进行到当前生命周期的时候来调用我们自定义的* 构造方法:* 单实例:在容器启动的时候创建对象* 多实例:在每次获取的时候创建对象* 初始化* 对象创建好,并赋值好,调用初始化方法....* 销毁:* ...原创 2020-10-09 18:52:20 · 127 阅读 · 0 评论 -
09--组件注册-使用FactoryBean注册组件
import org.springframework.beans.factory.FactoryBean;public class MyFactoryBean implements FactoryBean<Color> { /** * 返回一个Color对象,这个对象会添加到容器中 */ @Override public Color getObject() throws Exception { // TODO Auto-generated method stub re.原创 2020-10-09 13:46:59 · 108 阅读 · 0 评论 -
08--组件注册-@Import-使用ImportBeanDefinitionRegistrar
import org.springframework.beans.factory.support.BeanDefinitionRegistry;import org.springframework.beans.factory.support.RootBeanDefinition;import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;import org.springframework.core.type.原创 2020-10-09 13:30:37 · 104 阅读 · 0 评论 -
07-组件注册-@Import-使用ImportSelector
import org.springframework.context.annotation.ImportSelector;import org.springframework.core.type.AnnotationMetadata;//自定义需要返回导入的数组public class MyImportSeletor implements ImportSelector { //返回值就是导入到容器中组件的全类名 @Override public String[] selectImport.原创 2020-10-09 13:11:56 · 149 阅读 · 0 评论 -
06--组件注册-@Conditional-按照条件注册bean
import org.springframework.beans.factory.config.ConfigurableBeanFactory;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.ComponentScan.Filter;i.原创 2020-10-09 12:45:41 · 105 阅读 · 0 评论 -
05--组件注册-@Lazy-bean懒加载
import org.springframework.beans.factory.config.ConfigurableBeanFactory;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.ComponentScan.Filter;i.原创 2020-10-09 11:38:55 · 100 阅读 · 0 评论 -
04--组件注册-@Scope-设置组件作用域
import org.springframework.beans.factory.config.ConfigurableBeanFactory;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.ComponentScan.Filter;i.原创 2020-10-09 11:29:28 · 76 阅读 · 0 评论 -
03--组件注册-自定义TypeFilter指定过滤规则
//配置类==配置文件(xml)@Configuration //告诉Spring这个一个配制类@ComponentScan(value="com.ceshi",includeFilters={ @Filter(type=FilterType.CUSTOM,classes={ MyFilterType.class })}) //value:指定要扫描的包。//excludeFilters=Filter[] 扫描排除//includeFilters=Filter[] 只扫描..原创 2020-10-09 11:14:31 · 945 阅读 · 0 评论 -
02-@ComponentScan-自动扫描组件&指定扫描规则
@Controllerpublic class PersonController {}@Repositorypublic class PersonDao {}@Servicepublic class PersonService {}//配置类==配置文件(xml)@Configuration //告诉Spring这个一个配制类@ComponentScan(value="com.ceshi",includeFilters={ @Filter(type=Filt.原创 2020-10-09 10:30:11 · 432 阅读 · 0 评论 -
01--Spring容器组件--@Configuration和@Bean
01、@Configuration和@Beanpublic class PersonBean { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { ...原创 2020-10-09 09:35:43 · 79 阅读 · 0 评论 -
Spring春天
Spring的博客分三个部分,第一部分Spring的应用第二部分Spring结构的设计第三部分Spring重要接口的翻译原创 2020-10-09 08:47:23 · 297 阅读 · 0 评论