文件db.propertis
user=root
password=root123
driver=com.mysql.jdbc.Driver
sb=123
<context:property-placeholder location="classpath:db.properties"/>
<bean id="p1" class="com.igeek.lesson8.Person">
<property name="userName" value="${user}"></property>
<property name="password" value="${password}"></property>
<property name="driver" value="${driver}"></property>
<property name="sb" value="${sb}"></property>
</bean>
ApplicationContext ac = new ClassPathXmlApplicationContext("com/igeek/lesson8/beans.xml");
Person bean = (Person) ac.getBean("p2");
System.out.println(bean);
输出结果:
Person [userName=root, password=root123, driver=com.mysql.jdbc.Driver, sb=123]
网友评论