Спокойной ночи. У меня есть непонятная ошибка при инъекции объекта, и я не понимаю, что это такое и как это избежать, поиск в Интернете не дал никаких результатов, ни одно решение не помогло. Буду признателен, если вы объясните причину.Весна необычная ошибка
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
Проблема заключается в конструкторе для 'jpaDao'. Вы должны показать нам это тоже. Предпочтительно, с указанием, какая линия является номером 24. –
Вы предоставили полное тело 'JpaReminder'? Если нет, пожалуйста. В противном случае вы могли бы также предоставить свой 'applicationContext.xml'? – sp00m