【Spring】依赖注入 加载顺序

时间:2024-01-03 20:55:20

一、Spring依赖注入depents-on参数

depents-on是指指定Bean初始化及销毁时的顺序,使用depends-on属性指定的是Bean要先初始化完毕后才初始化当前Bean,由于只有Singleton Bean能被Spring管理销毁,所以当指定的Bean都是singleton时,使用depends-on属性指定的Bean要在指定的Bean之后销毁

1、需要实体类以及配置文件测试实例 日志信息

 package com.slp.spring.learn.helloworld.di;

 import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* ResourceBean从配置文件中配置文件位置,然后定义初始化方法init中打开指定的文件,然后获取文件流;最后定义销毁方法destroy用于在应用程序关闭时调用该方法关闭掉文件流
* @author sangliping
*
*/
public class ResourceBean { private FileOutputStream fos;
private File file;
public void init(){
System.out.println("ResourceBean:=============初始化");
//加载资源,在此只是演示
System.out.println("ResourceBean:==============加载资源,执行一些与操作");
try {
fos=new FileOutputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public void destory(){
System.out.println("ResourceBean:============销毁");
//释放资源
System.out.println("ResourceBean:===========释放资源,执行一些清理操作");
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public FileOutputStream getFos() {
return fos;
} public void setFos(FileOutputStream fos) {
this.fos = fos;
} public File getFile() {
return file;
} public void setFile(File file) {
this.file = file;
} }
package com.slp.spring.learn.helloworld.di;

import java.io.IOException;
/**
* DependentBean中会注入ResourceBean,并从ResourceBean中获取文件流写入内容;定义初始化方法init用来定义一些初始化操作并向文件中输出文件头信息;最后定义销毁方法用于在关闭应用程序时想文件中输出文件尾信息。
* @author sangliping
*
*/
public class DependentBean {
ResourceBean resourceBean; public void write(String ss) throws IOException {
System.out.println("DependentBean:=======写资源");
resourceBean.getFos().write(ss.getBytes());
} // 初始化方法
public void init() throws IOException {
System.out.println("DependentBean:=======初始化");
resourceBean.getFos().write("DependentBean:=======初始化=====".getBytes());
} // 销毁方法
public void destroy() throws IOException {
System.out.println("DependentBean:=======销毁");
// 在销毁之前需要往文件中写销毁内容
resourceBean.getFos().write("DependentBean:=======销毁=====".getBytes());
} public void setResourceBean(ResourceBean resourceBean) {
this.resourceBean = resourceBean;
}
}
<?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-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="resourceBean" class="com.slp.spring.learn.helloworld.di.ResourceBean" init-method="init" destroy-method="destory">
<property name="file" value="D://test.txt"></property><!-- Spring容器可以自动把字符串转换为java.io.File -->
</bean>
<bean id="dependentBean" class="com.slp.spring.learn.helloworld.di.DependentBean" init-method="init" destroy-method="destroy" depends-on="resourceBean">
<property name="resourceBean" ref="resourceBean"></property>
</bean>
</beans>
package com.slp.spring.learn.helloworld.di;

import java.io.IOException;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/*2017-07-13 10:28:39,793 DEBUG main org.springframework.core.env.MutablePropertySources.addLast(MutablePropertySources.java:107) Adding [systemProperties] PropertySource with lowest search precedence
2017-07-13 10:28:39,884 DEBUG main org.springframework.core.env.MutablePropertySources.addLast(MutablePropertySources.java:107) Adding [systemEnvironment] PropertySource with lowest search precedence
2017-07-13 10:28:39,885 DEBUG main org.springframework.core.env.AbstractEnvironment.<init>(AbstractEnvironment.java:126) Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2017-07-13 10:28:39,918 INFO main org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:510) Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7c30a502: startup date [Thu Jul 13 10:28:39 CST 2017]; root of context hierarchy
2017-07-13 10:28:40,080 DEBUG main org.springframework.core.env.MutablePropertySources.addLast(MutablePropertySources.java:107) Adding [systemProperties] PropertySource with lowest search precedence
2017-07-13 10:28:40,081 DEBUG main org.springframework.core.env.MutablePropertySources.addLast(MutablePropertySources.java:107) Adding [systemEnvironment] PropertySource with lowest search precedence
2017-07-13 10:28:40,086 DEBUG main org.springframework.core.env.AbstractEnvironment.<init>(AbstractEnvironment.java:126) Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2017-07-13 10:28:40,196 INFO main org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:315) Loading XML bean definitions from class path resource [di/depent-on.xml]
2017-07-13 10:28:40,201 DEBUG main org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:72) Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
2017-07-13 10:28:40,382 DEBUG main org.springframework.beans.factory.xml.PluggableSchemaResolver.getSchemaMappings(PluggableSchemaResolver.java:140) Loading schema mappings from [META-INF/spring.schemas]
2017-07-13 10:28:40,394 DEBUG main org.springframework.beans.factory.xml.PluggableSchemaResolver.getSchemaMappings(PluggableSchemaResolver.java:146) Loaded schema mappings: {http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd=org/springframework/oxm/config/spring-oxm-3.0.xsd, http://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.2.xsd, http://www.springframework.org/schema/jee/spring-jee-3.2.xsd=org/springframework/ejb/config/spring-jee-3.2.xsd, http://www.springframework.org/schema/jms/spring-jms-3.0.xsd=org/springframework/jms/config/spring-jms-3.0.xsd, http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd=org/springframework/web/servlet/config/spring-mvc-3.1.xsd, http://www.springframework.org/schema/task/spring-task.xsd=org/springframework/scheduling/config/spring-task-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd, http://www.springframework.org/schema/cache/spring-cache.xsd=org/springframework/cache/config/spring-cache-3.2.xsd, http://www.springframework.org/schema/aop/spring-aop-3.0.xsd=org/springframework/aop/config/spring-aop-3.0.xsd, http://www.springframework.org/schema/task/spring-task-3.1.xsd=org/springframework/scheduling/config/spring-task-3.1.xsd, http://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd, http://www.springframework.org/schema/oxm/spring-oxm.xsd=org/springframework/oxm/config/spring-oxm-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd, http://www.springframework.org/schema/jee/spring-jee-2.5.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd=org/springframework/jdbc/config/spring-jdbc-3.1.xsd, http://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd, http://www.springframework.org/schema/jee/spring-jee-3.1.xsd=org/springframework/ejb/config/spring-jee-3.1.xsd, http://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-3.2.xsd, http://www.springframework.org/schema/tx/spring-tx-3.2.xsd=org/springframework/transaction/config/spring-tx-3.2.xsd, http://www.springframework.org/schema/context/spring-context-3.2.xsd=org/springframework/context/config/spring-context-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd, http://www.springframework.org/schema/util/spring-util-3.2.xsd=org/springframework/beans/factory/xml/spring-util-3.2.xsd, http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd=org/springframework/web/servlet/config/spring-mvc-3.0.xsd, http://www.springframework.org/schema/lang/spring-lang-3.2.xsd=org/springframework/scripting/config/spring-lang-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd, http://www.springframework.org/schema/cache/spring-cache-3.2.xsd=org/springframework/cache/config/spring-cache-3.2.xsd, http://www.springframework.org/schema/task/spring-task-3.0.xsd=org/springframework/scheduling/config/spring-task-3.0.xsd, http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd=org/springframework/oxm/config/spring-oxm-3.2.xsd, http://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd, http://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd=org/springframework/jdbc/config/spring-jdbc-3.0.xsd, http://www.springframework.org/schema/jms/spring-jms-3.2.xsd=org/springframework/jms/config/spring-jms-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd, http://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-3.2.xsd, http://www.springframework.org/schema/lang/spring-lang.xsd=org/springframework/scripting/config/spring-lang-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd, http://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd, http://www.springframework.org/schema/lang/spring-lang-2.5.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd, http://www.springframework.org/schema/aop/spring-aop-3.2.xsd=org/springframework/aop/config/spring-aop-3.2.xsd, http://www.springframework.org/schema/jee/spring-jee-3.0.xsd=org/springframework/ejb/config/spring-jee-3.0.xsd, http://www.springframework.org/schema/tx/spring-tx-3.1.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd, http://www.springframework.org/schema/jee/spring-jee-2.0.xsd=org/springframework/ejb/config/spring-jee-2.0.xsd, http://www.springframework.org/schema/context/spring-context-3.1.xsd=org/springframework/context/config/spring-context-3.1.xsd, http://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd, http://www.springframework.org/schema/lang/spring-lang-3.1.xsd=org/springframework/scripting/config/spring-lang-3.1.xsd, http://www.springframework.org/schema/cache/spring-cache-3.1.xsd=org/springframework/cache/config/spring-cache-3.1.xsd, http://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.2.xsd, http://www.springframework.org/schema/jee/spring-jee.xsd=org/springframework/ejb/config/spring-jee-3.2.xsd, http://www.springframework.org/schema/jms/spring-jms-2.5.xsd=org/springframework/jms/config/spring-jms-2.5.xsd, http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd=org/springframework/oxm/config/spring-oxm-3.1.xsd, http://www.springframework.org/schema/jms/spring-jms.xsd=org/springframework/jms/config/spring-jms-3.2.xsd, http://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsd, http://www.springframework.org/schema/mvc/spring-mvc.xsd=org/springframework/web/servlet/config/spring-mvc-3.2.xsd, http://www.springframework.org/schema/jms/spring-jms-3.1.xsd=org/springframework/jms/config/spring-jms-3.1.xsd, http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd=org/springframework/web/servlet/config/spring-mvc-3.2.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc.xsd=org/springframework/jdbc/config/spring-jdbc-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-3.2.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd, http://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd, http://www.springframework.org/schema/aop/spring-aop-3.1.xsd=org/springframework/aop/config/spring-aop-3.1.xsd, http://www.springframework.org/schema/task/spring-task-3.2.xsd=org/springframework/scheduling/config/spring-task-3.2.xsd, http://www.springframework.org/schema/tx/spring-tx-3.0.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd, http://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd, http://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.2.xsd, http://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd, http://www.springframework.org/schema/lang/spring-lang-3.0.xsd=org/springframework/scripting/config/spring-lang-3.0.xsd, http://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd, http://www.springframework.org/schema/lang/spring-lang-2.0.xsd=org/springframework/scripting/config/spring-lang-2.0.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd=org/springframework/jdbc/config/spring-jdbc-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool-3.2.xsd=org/springframework/beans/factory/xml/spring-tool-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd}
2017-07-13 10:28:40,398 DEBUG main org.springframework.beans.factory.xml.PluggableSchemaResolver.resolveEntity(PluggableSchemaResolver.java:118) Found XML schema [http://www.springframework.org/schema/beans/spring-beans-3.0.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-3.0.xsd
2017-07-13 10:28:40,633 DEBUG main org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:106) Loading bean definitions
2017-07-13 10:28:40,698 DEBUG main org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216) Loaded 2 bean definitions from location pattern [di/depent-on.xml]
2017-07-13 10:28:40,700 DEBUG main org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540) Bean factory for org.springframework.context.support.ClassPathXmlApplicationContext@7c30a502: org.springframework.beans.factory.support.DefaultListableBeanFactory@1e6d1014: defining beans [resourceBean,dependentBean]; root of factory hierarchy
2017-07-13 10:28:40,763 DEBUG main org.springframework.context.support.AbstractApplicationContext.initMessageSource(AbstractApplicationContext.java:807) Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@7a187f14]
2017-07-13 10:28:40,817 DEBUG main org.springframework.context.support.AbstractApplicationContext.initApplicationEventMulticaster(AbstractApplicationContext.java:831) Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@27808f31]
2017-07-13 10:28:40,818 INFO main org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:603) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1e6d1014: defining beans [resourceBean,dependentBean]; root of factory hierarchy
2017-07-13 10:28:40,820 DEBUG main org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:215) Creating shared instance of singleton bean 'resourceBean'
2017-07-13 10:28:40,821 DEBUG main org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:432) Creating instance of bean 'resourceBean'
2017-07-13 10:28:40,844 DEBUG main org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:506) Eagerly caching bean 'resourceBean' to allow for resolving potential circular references
2017-07-13 10:28:40,936 DEBUG main org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1612) Invoking init method 'init' on bean with name 'resourceBean'
ResourceBean:=============初始化
ResourceBean:==============加载资源,执行一些与操作
2017-07-13 10:28:40,966 DEBUG main org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:460) Finished creating instance of bean 'resourceBean'
2017-07-13 10:28:40,967 DEBUG main org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246) Returning cached instance of singleton bean 'resourceBean'
2017-07-13 10:28:40,972 DEBUG main org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:215) Creating shared instance of singleton bean 'dependentBean'
2017-07-13 10:28:40,972 DEBUG main org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:432) Creating instance of bean 'dependentBean'
2017-07-13 10:28:40,974 DEBUG main org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:506) Eagerly caching bean 'dependentBean' to allow for resolving potential circular references
2017-07-13 10:28:40,977 DEBUG main org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246) Returning cached instance of singleton bean 'resourceBean'
2017-07-13 10:28:40,980 DEBUG main org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1612) Invoking init method 'init' on bean with name 'dependentBean'
DependentBean:=======初始化
2017-07-13 10:28:40,982 DEBUG main org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:460) Finished creating instance of bean 'dependentBean'
2017-07-13 10:28:40,984 DEBUG main org.springframework.context.support.AbstractApplicationContext.initLifecycleProcessor(AbstractApplicationContext.java:858) Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@b3d7190]
2017-07-13 10:28:40,985 DEBUG main org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246) Returning cached instance of singleton bean 'lifecycleProcessor'
2017-07-13 10:28:40,995 DEBUG main org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:81) Searching for key 'spring.liveBeansView.mbeanDomain' in [systemProperties]
2017-07-13 10:28:41,023 DEBUG main org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:81) Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
2017-07-13 10:28:41,028 DEBUG main org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:103) Could not find key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [null]
2017-07-13 10:28:41,066 DEBUG main org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246) Returning cached instance of singleton bean 'dependentBean'
DependentBean:=======写资源
2017-07-13 10:28:41,114 INFO Thread-0 org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1042) Closing org.springframework.context.support.ClassPathXmlApplicationContext@7c30a502: startup date [Thu Jul 13 10:28:39 CST 2017]; root of context hierarchy
2017-07-13 10:28:41,116 DEBUG Thread-0 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246) Returning cached instance of singleton bean 'lifecycleProcessor'
2017-07-13 10:28:41,116 INFO Thread-0 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:444) Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1e6d1014: defining beans [resourceBean,dependentBean]; root of factory hierarchy
2017-07-13 10:28:41,116 DEBUG Thread-0 org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:303) Invoking destroy method 'destroy' on bean with name 'dependentBean'
DependentBean:=======销毁
2017-07-13 10:28:41,117 DEBUG Thread-0 org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:303) Invoking destroy method 'destory' on bean with name 'resourceBean'
ResourceBean:============销毁
ResourceBean:===========释放资源,执行一些清理操作
*/
public class MoreDependencyInjectTest { @Test
public void testDependOn() throws IOException{
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("di/depent-on.xml");
//注册销毁回调 否则定义的销毁方法不执行
context.registerShutdownHook();
DependentBean dependent = context.getBean("dependentBean", DependentBean.class);
dependent.write("测试写入数据");
}
}