GoogleSearchBox

Custom Search

Wednesday, June 26, 2013

Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument

Error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ticketRegistry' defined in ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver

 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)

Solution:
If you are using Hibernate 3.5 or above, You should remove the dependency on hibernate-annotations from your maven pom file.

If you got this while building CAS server using the root pom file.

Try removing any spring related dependencies mentioned in the projects root POM file. Internally the CAS will download all the spring dependencies.

Also, add the corresponding Database driver jar file. Or add it to your pom's dependency.
e.g.:
For adding MySQL Server driver, the Maven's POM dependency would be:

  <dependency>

   <groupId>mysql</groupId>

   <artifactId>mysql-connector-java</artifactId>

   <version>5.1.13</version>

   <scope>runtime</scope>

  </dependency>

References: