【问题标题】:Error creating bean with name 'dao'创建名为“dao”的 bean 时出错
【发布时间】:2015-06-24 10:35:24
【问题描述】:

我不知道啊,当我想使用 spring bean 测试我的应用程序时,我遇到了这个错误,这是主要测试: 公共类测试 {

public static void main(String[] args) {
    ClassPathXmlApplicationContext context=
    new ClassPathXmlApplicationContext(new String[]  
    {"applicationContext.xml"});
    IBanqueMetier metier=(IBanqueMetier) context.getBean("metier");
    metier.addClient(new Client("C1", "AD1"));
    metier.addClient(new Client("C2", "AD2"));
}

这是第一个错误:

Exception in thread   "main"org.springframework.beans.factory.BeanCreationException:
      Error creating bean with name 'dao': Injection of persistence dependencies

failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: org.gestion.bp.entities.Compte.employe
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:342)
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:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)

【问题讨论】:

  • 您的意思是错误消息“非法尝试将非集合映射为 OneToMany、ManyToMany 或 CollectionOfElements:org.gestion.bp.entities.Compte.employe”?还有?

标签: eclipse spring maven jakarta-ee jpa


【解决方案1】:

对于 Spring 例外情况,您务必要通读整条消息,直到最后。我通常将消息分成几行以使其更具可读性:

Exception in thread   "main"org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dao': Injection of persistence dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]:
Invocation of init method failed;
nested exception is org.hibernate.AnnotationException:
Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements:
org.gestion.bp.entities.Compte.employe

如您所见,您在字段org.gestion.bp.entities.Compte.employe的定义中出错了

【讨论】:

    猜你喜欢
    • 2021-11-28
    • 2020-10-03
    • 2019-08-28
    • 2015-03-18
    • 2021-03-17
    • 2021-06-18
    • 2019-07-21
    • 2016-04-04
    • 2019-11-15
    相关资源
    最近更新 更多