English 中文(简体)
春豆树例外:不能解决提及豆类例外的问题
原标题:Spring BeanCreationException: cannot resolve reference to bean exception
  • 时间:2013-01-02 15:02:39
  •  标签:
  • spring
I am trying the example application at the following web site: JSF 2, PrimeFaces 3, Spring 3 & Hibernate 4 Integration Project But I find that when running the project, I get: SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name UserService defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean UserDAO while setting bean property userDAO ; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name UserDAO defined in ServletContext resource [/WEB-INF/applicationContext.xml] However, in the applicationContext.xml file, the relevant code is as follows: com.otv.model.User org.hibernate.dialect.MySQLDialect true The classes do exist in the relevant packages as well as can be seen below and the location of the various config files. The only difference I can see between the tutorial and my implementation of it is that I am using NetBeans 7.2 rather than Eclipse. Has anyone any idea as to why this is?
问题回答
/WEB-INF/applicationContext.xml should contain an entry like ... whose properties largely depend on the backend system used. I also suspect that the User bean is a bad copy and past as User instances should be retrived from the DAO or created programmatically. As to why it works in Eclipse and not in Netbeans, it is too strange to be true. There must be some clutter...
I found the main cause of that error. It is actually quit simple. In the class com.otv.model.User, there is no @Id annotation above the field id. Here is the link for the answer that lead me to find what was the mistake : hibernate exception: org.hibernate.AnnotationException: No identifier specified for entity: com..domain.idea.MAE_MFEView
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name UserService defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean UserDAO while setting bean property userDAO ; This is telling you that UserService can t be created because its missing a property definition nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name UserDAO defined in ServletContext resource [/WEB-INF/applicationContext.xml] This tells you that the definition for UserDAO can t be found. You are missing the UserDao definition, the ref just means that it should be of that type, it still needs a bean definition. Basically, whenever you use "ref" you are telling spring to make a property of that type. That type needs to be defined in its own bean definition. So if UserDao uses some other property that again is defined by a "ref" that property will need its own bean definition as well. You have to think of the classes and the spring definitions to be two completely separate entities. The classes might be there and placed where they should, but spring needs its bean definitions in order to invoke them. It doesn t know what a UserDao or SessionFactory is unless you specifically tell it which package/class you want to be invoked.




相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签