spring的一些基础及aop配置元素

在这里插入图片描述
配置bean基于xml

  1. 实例化方式
    1.默认构造必须提供默认构造,
    2.静态工厂 :a.整合其他框架
    b.用于生产实例对象,所有方法必须是static(懒汉,恶汉方式)
    c.
    3.工厂
实现类
public class UserServiceimpl implements UserService {

	@Override
	public void run() {
		System.out.println("大家好我是菜虚昆,喜欢崩跳,rap");
	}
public class Mybeanfactory {
	/*
	 * 创建实例
	 */
	public static UserService creatUserService(){
		return new  UserServiceimpl();
		
	}
}

2.bean种类
3.作用域
4.生命周期11个过程

  1. intantiate bean对象实例化

  2. public properties封装属性

  3. 如果bean实现 BeanNameAware 执行 setBeanName

  4. 如果Bean实现BeanFactoryAware 或者 ApplicationContextAware设置工厂setBeanFactory或者上下文对象setApplicatinContext

  5. 如果粗子啊类实现BeanPostProcessor,执行postProcessBeforeinitialization

  6. 如果Bean实现InitializaingBean执行afterPropertiesSet

  7. 调用知道初始化方法init

  8. 如果存在类实现BeanpostProcessor,执行postProcessAfterInitialization

  9. 执行业务处理

  10. 如果Bean实现DisposableBean执行destory

  11. 调用指定销毁方法customerDestory

    4.1初始化和销毁

5.属性的依赖注入

1. seet属性注入
bean的xml配置
在这里插入图片描述
2p命名空间
在这里插入图片描述
3.spel(spring语言表达式)
在这里插入图片描述
4.集合注入
属性注入集合

	private String[] arraydate;
	private List<String> list;
	private  Set<String> setdata;
	private Map<String,String> mapdata;
	private Properties propsdata;

1.array
在这里插入图片描述

2.list集合
在这里插入图片描述

3.set注入

在这里插入图片描述

4.map

在这里插入图片描述

5.properties属性
在这里插入图片描述

装配bean基于注解
在xml中配置好后,spring会进行扫描带有注解的类

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.2.xsd">

  
  <!-- 注解配置,主键扫描,含有注解的类-->
  <context:component-scan base-package="com.wenhe.zhujie"></context:component-scan>
</beans>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值