-
Jul 6th, 2006, 11:42 AM
#1
AbstractTransactionalDataSourceSpringContextTests UnsatisfiedDependencyException
Sorry if this is a repeat question.
I am new to Spring (I love it), I am trying the Appfuse application. I am using Eclipse3.1.2, have src, test folders. Spring-Version: 1.2.6. The test classes are in test src. my dao classes are in src folder. my context files are in WEB-INF folder
Instead of Person, I have Client and I am getting the following error when trying to run the ClientDaoTest:
org.springframework.beans.factory.UnsatisfiedDepen dencyException: Error creating bean with name 'org.appfuse.test.dao.ClientDaoTest' defined in null: Unsatisfied dependency expressed through bean property 'clientDao': set this property value or disable dependency checking for this bean
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.checkDependencies(Abstr actAutowireCapableBeanFactory.java:962)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:823)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireBeanProperties( AbstractAutowireCapableBeanFactory.java:200)
at org.springframework.test.AbstractDependencyInjecti onSpringContextTests.setUp(AbstractDependencyInjec tionSpringContextTests.java:201)
at junit.framework.TestCase.runBare(TestCase.java:125 )
at junit.framework.TestResult$1.protect(TestResult.ja va: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:2 08)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)
Here is my applicationContext-hibernate.xml:
<!-- ClientDao: Hibernate implementation -->
<bean id="clientDao" class="org.appfuse.dao.hibernate.ClientDaoHibernat e">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
Here is my ClientDaoTest:
public class ClientDaoTest extends BaseDaoTestCase {
protected Client client = null;
protected ClientDao dao = null;
public void setClientDao(ClientDao dao){
this.dao = dao;
}
public void testGetClient() throws Exception{
client = new Client();
client.setFirstName("A");
client.setLastName("BC");
client.setEmail("abc@homail.com");
dao.saveClient(client);
assertEquals(client.getFirstName(), "A");
}
Here is my BaseDaoTestCase
public abstract class BaseDaoTestCase extends AbstractTransactionalDataSourceSpringContextTests {
protected final Log log = LogFactory.getLog(getClass());
protected ResourceBundle rb;
protected String[] getConfigLocations() {
setAutowireMode(AUTOWIRE_BY_TYPE);
return new String [] {"classpath*:/WEB-INF/applicationContext-*.xml",
"classpath*:META-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 Object populated object
* @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;
}
}
Any ideas.
Thank you very much.
-
Jul 6th, 2006, 03:47 PM
#2
I found the problem. It was not reading the context files which were located under WEB-INF folder. I moved to src folder and boom the error disappeared.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules