Salve "Could not find dependency for key" during Spring initialization

62 views
Skip to first unread message

Alec Swan

unread,
Jun 28, 2010, 9:39:09 PM6/28/10
to salve...@googlegroups.com
Hello,

I am using Salve in my project and it has been working great.

Today I decided to add a "clock" field annotated with @Dependency to a
persistence class IdentifiableModel which is also annotated with JPA
annotations. This didn't work and the error is shown below. I believe
what happens is that the app starts up and initializes Spring. Spring,
in turn tries to instantiate "test object" OfferRecipient which is a
sub-class of IdentifiableModel. This causes @Dependency-annotated
"clock" field to get injected, but since Spring context is not yet
initialized, Salve cannot resolve the dependency.

How can I fix this?

Thanks

2010-06-28 19:26:22,848 MDT ERROR [main]
org.springframework.test.context.TestContextManager - Caught exception
while allowing TestExecutionListener
[org.springframework.test.context.support.DependencyInjectionTestExecutionListener@2709da]
to prepare test instance
[com.galecsy.lrm.wicket.offer.templates.OfferingsPageUnitTest@ced1ac]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:201)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:111)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:148)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:36)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:420)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:911)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:768)
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in class path
resource [WEB-INF/config/lrm-service.xml]: Invocation of init method
failed; nested exception is org.hibernate.InstantiationException:
could not instantiate test
objectcom.galecsy.lrm.domain.model.OfferRecipient
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:42)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:173)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:197)
... 15 more
Caused by: org.hibernate.InstantiationException: could not instantiate
test objectcom.galecsy.lrm.domain.model.OfferRecipient
at org.hibernate.engine.UnsavedValueFactory.instantiate(UnsavedValueFactory.java:48)
at org.hibernate.engine.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:67)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:67)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:136)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:456)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 31 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.hibernate.engine.UnsavedValueFactory.instantiate(UnsavedValueFactory.java:45)
... 45 more
Caused by: java.lang.RuntimeException:
salve.depend.DependencyNotFoundException: Could not find dependency
for key: [FieldKey
field=com.galecsy.lrm.domain.model.IdentifiableModel#clock]
at salve.depend.DependencyAspect.handleRead(DependencyAspect.aj:59)
at salve.depend.DependencyAspect.ajc$inlineAccessMethod$salve_depend_DependencyAspect$salve_depend_DependencyAspect$handleRead(DependencyAspect.aj:1)
at com.galecsy.lrm.domain.model.IdentifiableModel.clock_aroundBody1$advice(IdentifiableModel.java:25)
at com.galecsy.lrm.domain.model.IdentifiableModel.<init>(IdentifiableModel.java:51)
at com.galecsy.lrm.domain.model.OfferRecipient.<init>(OfferRecipient.java:43)
... 50 more
Caused by: salve.depend.DependencyNotFoundException: Could not find
dependency for key: [FieldKey
field=com.galecsy.lrm.domain.model.IdentifiableModel#clock]
at salve.depend.DependencyLibrary.locate(DependencyLibrary.java:107)
at salve.depend.DependencyAspect.handleRead(DependencyAspect.aj:52)
... 54 more

Reply all
Reply to author
Forward
0 new messages