spring
文章平均质量分 92
珂-瑞
这个作者很懒,什么都没留下…
展开
-
Spring注解驱动
Spring注解驱动转载 2022-07-19 07:33:49 · 417 阅读 · 0 评论 -
11-Spring AOP功能(1)
【AOP动态代理】:指在程序运行期间动态的将某段代码切入到指定方法、指定位置进行运行的编程方式。下面以实例说明在类MathCalculator中div()方法中加入切面package com.spring.aop;public class MathCalculator { public int div(int i,int j){ System.out....原创 2020-03-30 21:58:59 · 141 阅读 · 0 评论 -
10-自动装配
1、@Autowired:Spring利用依赖注入(DI),完成对IOC容器中各个组件的依赖关系赋值1)、默认优先按照类型去容器中找对应的组件:annotationConfigApplicationContext.getBean(BookService.class)2)、如果找到多个相同各类型的组件,再将属性的名称作为组件的id,去容器中查找。3)、@Qualifier: //指定...原创 2020-03-30 16:51:56 · 267 阅读 · 0 评论 -
09-属性赋值
以前使用xml方法配置文件中,为Bean的属性赋值的方法使用<property>方式<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/X...原创 2020-03-29 18:41:10 · 137 阅读 · 0 评论 -
08-Bean的生命周期
使用Spring提供的FactoryBean(工厂Bean)原创 2020-03-29 01:22:09 · 170 阅读 · 0 评论 -
07-组件注册-@Import、@ImportSelector、@ImportBeanDefinitionRegistrar及FactoryBean工厂方式,给容器中导入一个组件
给容器中注册组件方式包扫描+组件标注注解(@Controller/@Service/@Repository/@Component)【局限于自己创建的类】 @Bean【导入的第三方包里面的组件】 @Import【快速给容器中导入一个第三方组件】为了测试方便,我们自己创建类Color和Red类,通过import导入进来。原创 2020-03-29 00:04:30 · 216 阅读 · 0 评论 -
06-组件注册-@Conditional-按照条件注册bean
@Conditional:按照一定的条件进行判断,满足条件给容器中注册bean组件。(Spring4.0之后加入了,并且大量使用)。现在实现一个功能根据操作系统不同给容器注册不同的Bean-如果系统是windows ,给容器中注册Person("lisi")-如果系统linux ,给容器中注册Person("wangwu")1、首先创建注册类@Configurationp...原创 2020-03-28 23:44:16 · 194 阅读 · 0 评论 -
05-组件注册-@Lazy-bean懒加载
上次说到,@Scope("singleton")或者不写默认是单实例方式,ioc容器启动时,会调用方法创建对象放到ioc容器中。但是可以使用懒加载方式,让ioc容器启动时,不创建对象,在第一次使用时,再去创建对象放到ioc容器,只需要添加@Lazyok,我们看代码。 @Lazy @Bean public Person person(){ System....原创 2020-03-28 22:07:46 · 168 阅读 · 0 评论 -
04-组件注册-@Scope-设置组件作用域
使用@sope可以调整组件作用域,有四种作用域 prototype: 多实例的,ioc容器启动并不会去调用方法创建对象在容器中,每次获取的时候才会调用方法创建对象。 singleton: 单实例的(默认值) ioc容器启动会调用方法创建对象放到ioc容器中以后每次获取就直接从容器(map.get())中拿。 request 同一次请求创建一个实例,web项目使用 ...原创 2020-03-28 21:32:17 · 205 阅读 · 0 评论 -
03-组件注册-@ComponentScan自定义TypeFilter指定过滤规则
组件注册也可以使用其他过滤规则//配置文件=配置类@Configuration //告诉Spring 这是一个配置类@ComponentScan(value = "com.spring", includeFilters = { //@ComponentScan.Filter(type = FilterType.ANNOTATION,classes ={Co...原创 2020-03-28 17:35:49 · 1131 阅读 · 0 评论 -
02-组件注册-@ComponentScan-自动扫描组件&指定扫描规则
实际在开发中包扫描用的比较多,注解为@ComponentScan。@ComponentScan(value = "com.spring", excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,classes ={Controller.class, Service.class})}, ...原创 2020-03-28 11:53:17 · 324 阅读 · 0 评论 -
01-组件注册-@Configuration&@Bean给容器中注册组件
spring给容器中注册组件方式首先创建springmaven项目,项目结构如下:pom.xml 加入spring配置<dependencies> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <depe...原创 2020-03-28 10:27:58 · 134 阅读 · 0 评论