Spring <bean>
使用spring
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");
IDISK idisk = (IDISK)context.getBean("disk");//根据配置文件的内容实例化对象并返回
配置文件
scope="prototype"取消单态,延迟加载只针对单态的bean适用,非单态的bean本来就是“延迟加载”
<bean id="dbreader" class="reader.DBReader" scope="prototype">
<!-- 构造方法注入
<constructor-arg index="0" type="java.lang.String">
<value>sfk</value>
</constructor-arg>
<constructor-arg index="1" type="java.lang.String">
<value>sfk</value>
</constructor-arg>
-->
<property name="driverClassname">
<value>sun.jdbc.odbc.JdbcOdbcDriver</value><!-- 属性注入 -->
</property>
<property name="url">
<value>url</value>
</property>
<property name="username">
<value>username</value>
</property>
<property name="password">
<value>password</value>
</property>
</bean>