首先看这个类:
package cn.edu.hpu.dao.Impl; import cn.edu.hpu.dao.UserDao; import cn.edu.hpu.model.User; public class UserDaoImpl implements UserDao{ private int daoId; private String daoStatus; public int getDaoId() { return daoId; } public void setDaoId(int daoId) { this.daoId = daoId; } public String getDaoStatus() { return daoStatus; } public void setDaoStatus(String daoStatus) { this.daoStatus = daoStatus; } public void save(User u) { System.out.println("add success!!"); } }
在类中我们确定不了daoId和daoStatus的值,但是在beans.xml中可以配置它的值。
配置方法如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="u" class="cn.edu.hpu.dao.Impl.UserDaoImpl"> <property name="daoId" value="8"></property> <property name="daoStatus" value="good"></property> </bean> </beans>
了解即可,很少用到。
什么样的Bean会用到呢?spring将来我们做整合的时候,spring它会给你提供一些它自己写好的bean。
举个例子:(数据库的连接池)
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- results in a setDriverClassName(String) call --> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/mydb</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>masterkaoli</value> </property> </bean>
转载请注明出处:http://blog.csdn.net/acmman
时间: 2024-09-15 07:24:17