floater wrote:
It's the first line:
It looks like you testcase has a property: personDAO and has dep checking enabled. Spring can't set this property and thus complains. make sure you have a setter for this property in your testcase and you have a valid ref to set this.
检查了没问题啊,master看得出问题在哪里吗?
PersonDAOTest.java
package org.appfuse.dao;
import org.appfuse.model.Person;
public class PersonDAOTest extends BaseDAOTestCase {
private Person person = null;
private PersonDAO dao = null;
public void setPersonDAO(PersonDAO dao) {
this.dao = dao;
}
public void testGetPerson() throws Exception {
person = new Person();
person.setFirstName("Matt");
person.setLastName("Raible");
dao.savePerson(person);
}
}
BaseDAOTestCase.java
package org.appfuse.dao;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Base class for running DAO tests.
* @author mraible
*/
public abstract class BaseDAOTestCase extends AbstractDependencyInjectionSpringContextTests {
protected final Log log = LogFactory.getLog(getClass());
protected ResourceBundle rb;
protected String[] getConfigLocations() {
return new String [] {"classpath*:/WEB-INF/applicationContext.xml"};
}
public BaseDAOTestCase() {
// Since a ResourceBundle is not required for each class, just
// do a simple check to see if one exists
String className = this.getClass().getName();
try {
rb = ResourceBundle.getBundle(className);
} catch (MissingResourceException mre) {
//log.warn("No resource bundle found for: " + className);
}
}
/**
* Utility method to populate a javabean-style object with values
* from a Properties file
* @param obj
* @return
* @throws Exception
*/
protected Object populate(Object obj) throws Exception {
// loop through all the beans methods and set its properties from
// its .properties file
Map map = new HashMap();
for (Enumeration keys = rb.getKeys(); keys.hasMoreElements();) {
String key = (String) keys.nextElement();
map.put(key, rb.getString(key));
}
BeanUtils.copyProperties(obj, map);
return obj;
}
}
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/config.properties</value>
</property>
</bean>
<!-- DataSoure -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>${hibernate.connection.driver_class}</value></property>
<property name="url"><value>${hibernate.connection.url}</value></property>
<property name="username"><value>${hibernate.connection.username}</value></property>
<property name="password"><value>${hibernate.connection.password}</value></property>
<property name="maxActive"><value>${hibernate.connection.maxActive}</value></property>
<property name="maxWait"><value>${hibernate.connection.maxWait}</value></property>
<property name="maxIdle"><value>${hibernate.connection.maxIdle}</value></property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>org/appfuse/model/Person.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop>
<prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
</props>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Generic DAO - can be used when doing standard CRUD -->
<bean id="dao" class="org.appfuse.dao.hibernate.BaseDAOHibernate">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- PersonDAO: Hibernate implementation -->
<bean id="PersonDAO" class="org.appfuse.dao.hibernate.PersonDAOHibernate">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Add new DAOs here -->
</beans>