Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Architecture & Framework  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 [求助]为AppFuse添加一个PersonDAOTest的单元测试,出现错误
down4u



Jute Pro User


发贴: 119
积分: 51
于 2005-10-31 15:59 user profilesend a private message to usersend email to down4usearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.appfuse.dao.PersonDAOTest' defined in null: Unsatisfied dependency expressed through bean property 'personDAO': set this property value or disable dependency checking for this bean
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.checkDependencies(AbstractAutowireCapableBeanFactory.java:961)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:822)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:200)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.setUp(AbstractDependencyInjectionSpringContextTests.java:138)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

不知道是因何而起?



作者 Re:[求助]为AppFuse添加一个PersonDAOTest的单元测试,出现错误 [Re:down4u]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2005-10-31 22:20 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
It's the first line:

Error creating bean with name 'org.appfuse.dao.PersonDAOTest' defined in null: Unsatisfied dependency expressed through bean property 'personDAO': set this property value or disable dependency checking for this bean

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.



"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler, Refactoring - Improving the Design of Existing Code
作者 Re:[求助]为AppFuse添加一个PersonDAOTest的单元测试,出现错误 [Re:floater]
down4u



Jute Pro User


发贴: 119
积分: 51
于 2005-11-01 11:31 user profilesend a private message to usersend email to down4usearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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>


down4u edited on 2005-11-01 11:35

作者 Re:[求助]为AppFuse添加一个PersonDAOTest的单元测试,出现错误 [Re:down4u]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2005-11-01 11:38 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
where is the line to set the dao(calling your setter)?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler, Refactoring - Improving the Design of Existing Code
作者 Re:[求助]为AppFuse添加一个PersonDAOTest的单元测试,出现错误 [Re:floater]
down4u



Jute Pro User


发贴: 119
积分: 51
于 2005-11-01 13:18 user profilesend a private message to usersend email to down4usearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
floater wrote:
where is the line to set the dao(calling your setter)?


不是这样的吗?这是照着appfuse的文档做的

小可初学,望master教我



作者 Re:[求助]为AppFuse添加一个PersonDAOTest的单元测试,出现错误 [Re:down4u]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2005-11-02 11:05 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
hmm, I didn't notice you are using spring's testcase class. change your dao declaration to protected, not using private.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler, Refactoring - Improving the Design of Existing Code
作者 Re:[求助]为AppFuse添加一个PersonDAOTest的单元测试,出现错误 [Re:floater]
down4u



Jute Pro User


发贴: 119
积分: 51
于 2005-11-02 11:36 user profilesend a private message to usersend email to down4usearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
floater wrote:
hmm, I didn't notice you are using spring's testcase class. change your dao declaration to protected, not using private.


org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.appfuse.dao.PersonDAOTest' defined in null: Unsatisfied dependency expressed through bean property 'personDAO': set this property value or disable dependency checking for this bean
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.checkDependencies(AbstractAutowireCapableBeanFactory.java:961)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:822)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:200)
  at org.springframework.test.AbstractDependencyInjectionSpringContextTests.setUp(AbstractDependencyInjectionSpringContextTests.java:138)
  at junit.framework.TestCase.runBare(TestCase.java:125)
  at junit.framework.TestResult$1.protect(TestResult.java:106)
  at junit.framework.TestResult.runProtected(TestResult.java:124)
  at junit.framework.TestResult.run(TestResult.java:109)
  at junit.framework.TestCase.run(TestCase.java:118)
  at junit.framework.TestSuite.runTest(TestSuite.java:208)
  at junit.framework.TestSuite.run(TestSuite.java:203)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)



作者 Re:[求助]为AppFuse添加一个PersonDAOTest的单元测试,出现错误 [Re:down4u]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2005-11-04 21:49 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
You testcase extends Matt's testcase, which extends Spring's testcase. This means that your dao class in your testcase will be injected by Spring(unless you want to manually inject it). Spring's super class will look for all protected members and inject them from app context. It doesn't check private members. So in you testcase, you should declare dao as protected, rather than private.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler, Refactoring - Improving the Design of Existing Code
作者 Re:[求助]为AppFuse添加一个PersonDAOTest的单元测试,出现错误 [Re:floater]
down4u



Jute Pro User


发贴: 119
积分: 51
于 2005-11-05 12:09 user profilesend a private message to usersend email to down4usearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
floater wrote:
You testcase extends Matt's testcase, which extends Spring's testcase. This means that your dao class in your testcase will be injected by Spring(unless you want to manually inject it). Spring's super class will look for all protected members and inject them from app context. It doesn't check private members. So in you testcase, you should declare dao as protected, rather than private.


private PersonDAO dao = null;改为protected PersonDAO dao = null;
可问题依旧,哎...




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923