UserDAOImpl.java:
package com.bjsxt.dao.impl; import com.bjsxt.dao.UserDAO;
import com.bjsxt.model.User; public class UserDAOImpl implements UserDAO {
/* (non-Javadoc)
* @see com.bjsxt.dao.UserDAO#save(com.bjsxt.model.User)
*/ 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 user) {
System.out.println("user saved!");
} @Override
public String toString() {
return this.daoId + ":" + this.daoStatus;
}
}
bean.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 name="userDAO" class="com.bjsxt.dao.impl.UserDAOImpl">
<property name="daoId" value="8"></property>
<property name="daoStatus" value="good"></property>
</bean> <bean id="userService" class="com.bjsxt.service.UserService">
<!--
<property name="userDAO">
<ref bean="userDAO"/>
</property>
-->
<constructor-arg>
<ref bean="userDAO"/>
</constructor-arg>
</bean>
</beans>
常用方法:
<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"/>
<property name="url" value="jdbc:mysql://localhost:3306/mydb"/>
<property name="username" value="root"/>
<property name="password" value="masterkaoli"/>
</bean>