2014-01-24 38 views
0

晚安。我在注入對象時有一個難以理解的錯誤,我不明白它是什麼以及如何避免,因特網搜索沒有返回結果,沒有任何解決方案沒有幫助。如果你能解釋原因,我將不勝感激。春天不尋常的錯誤

ReminderService豆

@Service("ReminderService") 
public class ReminderService implements dbService<Reminder> 
{ 
@Autowired 
private JpaReminder jpaReminder; 

@Transactional 
public List<Reminder> getAll() 
{ 
    return jpaReminder.findAll(); 
} 

@Transactional 
public Reminder get(Object id) 
{ 
    return jpaReminder.find(id); 
} 

} 

JpaReminder豆,

@Repository("JpaReminder") 
public class JpaReminder extends jpaDao<Reminder> 
{ 
private EntityManager em; 

/** 
* @return Возвращает entityManager 
*/ 
@Override 
protected EntityManager getEntityManager() 
{ 
    return em; 
} 

public EntityManager getEm() 
{ 
    return em; 
} 

@PersistenceContext(unitName = "TaskTracker") 
public void setEm(EntityManager em) 
{ 
    this.em = em; 
} 

} 

堆棧跟蹤誤差

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ReminderService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.work.Spring.Dao.JpaReminder com.work.Spring.mainClass.ReminderService.jpaReminder; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'JpaReminder' defined in file [/home/qwerty/Eclipse/Spring/target/classes/com/work/Spring/Dao/JpaReminder.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.work.Spring.Dao.JpaReminder]: Constructor threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: 1 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469) 
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
at com.work.Spring.App.main(App.java:22) 

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.work.Spring.Dao.JpaReminder com.work.Spring.mainClass.ReminderService.jpaReminder; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'JpaReminder' defined in file [/home/qwerty/Eclipse/Spring/target/classes/com/work/Spring/Dao/JpaReminder.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.work.Spring.Dao.JpaReminder]: Constructor threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: 1 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506) 
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284) 
... 13 more 

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'JpaReminder' defined in file [/home/qwerty/Eclipse/Spring/target/classes/com/work/Spring/Dao/JpaReminder.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.work.Spring.Dao.JpaReminder]: Constructor threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: 1 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735) 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478) 
... 15 more 

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.work.Spring.Dao.JpaReminder]: Constructor threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: 1 
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162) 
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:76) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990) 
... 26 more 

Caused by: java.lang.ArrayIndexOutOfBoundsException: 1 
at com.work.Interfaces.jpaDao.<init>(jpaDao.java:24) 
at com.work.Spring.Dao.JpaReminder.<init>(JpaReminder.java:19) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:532) 
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) 
... 28 more 
+3

問題出在'jpaDao'的構造函數中。你也需要向我們展示。最好用指示哪一行是數字24. –

+0

您提供了「JpaReminder」的全部內容嗎?如果不是,請做。否則,你可以提供你的'applicationContext.xml'嗎? – sp00m

回答

3

從異常的堆棧跟蹤,這是明顯的是JpaReminder的構造函數代碼拋出java.lang.ArrayIndexOutOfBoundsException: 1.

由於JpaReminder正在擴大jpaDaoJpaReminder沒有自己的構造然後,jpaDao的(或它的父類的)構造函數是罪魁禍首

您可以調試代碼並找出更多

0

我在我的應用程序中,當我使用Spring 8以下版本的Java 8時出現了類似的異常。我不得不升級到Spring 4或更改lambda表達式,所以我做了後者。

這很難知道,因爲錯誤太模糊了。與數組無關,真的。