.实现过程
1:添加jar包
<
groupId>org.springframework
spring-expression
5.0.8.RELEASE
2:创建配置文件application.xml
<?xml version="1.0" encoding="UTF-8"?>步骤3:在配置文件中创建对象
属性 说明
class --------------指定bean对应类的全路径
name ---------------name是bean对应对象的一个标识
scope ----------------执行bean对象创建模式和生命周期,scope="singleton"和scope=“prototype”
id ----------------id是bean对象的唯一标识,不能添加特别字符
lazy-init ---------------是否延时加载 默认值:false。true 延迟加载对象,当对象被调用的时候才会加载,测试
的时候,通过getbean()方法获得对象。lazy-init=“false” 默认值,不延迟,无论对象是否被使用,都会立即创建对象,测试时只需要加载配置文件即可。注意:测试的时候只留下id,class属性
initmethod -------------只需要加载配置文件即可对象初始化方法
destroymethod ----------对象销毁方法
步骤4:加载配置文件,获得对象
ApplicationContext app=new ClassPathXmlApplicationContext(“application.xml”);
app.getBean(“id标识”);