2013-10-17 136 views
1

我正在开发一个Spring应用程序,并在春天autowire配置中遇到问题。我无法解决这个问题。春天autowire配置问题

这是我的例外。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactsController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.venkatesh.service.ContactService com.venkatesh.controller.ContactsController.contactService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration 

这是我的Spring servlet.xml。我认为问题在这里。

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:c="http://www.springframework.org/schema/c" xmlns:context="http://www.springframework.org/schema/context" 
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" 
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" 
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd 
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd 
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd 
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"> 
<context:annotation-config></context:annotation-config> 
<context:component-scan base-package="com.venkatesh.controller"></context:component-scan> 
<context:component-scan base-package="com.venkatesh.service"></context:component-scan> 
<context:component-scan base-package="com.venkatesh.dao"></context:component-scan> 


<bean id="jspViewResolver" 
class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
<property name="viewClass" 
value="org.springframework.web.servlet.view.JstlView" /> 
<property name="prefix" value="/WEB-INF/jsp/" /> 
<property name="suffix" value=".jsp" /> 
</bean> 

<bean id="propertyConfigurer" 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" 
p:location="/WEB-INF/jdbc.properties" /> 

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}" 
p:username="${jdbc:username}"></bean> 

<bean id="sessionFactory" 
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
<property name="dataSource" ref="dataSource" /> 
<property name="configLocation"> 
<value>classpath:hibernate.cfg.xml</value> 
</property> 
<property name="configurationClass"> 
<value>org.hibernate.cfg.AnnotationConfiguration</value> 
</property> 
<property name="hibernateProperties"> 
<props> 
<prop key="hibernate.dialect">${jdbc.dialect}</prop> 
<prop key="hibernate.show_sql">true</prop> 
</props> 
</property> 
</bean> 
<tx:annotation-driven /> 
<bean id="transactionManager" 
class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
<property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

</beans> 

在此先感谢

+0

这似乎是你使用基于注释的注入你可以发布你的java代码,你实际上如何尝试.. –

+0

似乎你错过了在你的lib中的hibernate - *。jar。 – CHowdappaM

回答

1

例外说明了一切:java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

你丢失的Hibernate的Jar文件的一个或有错误的版本hibernate.jar。确保.jar文件包含在您的类路径中。

1

你肯定有hibernate.jar在classpath?解压hibernate.jar你的classpath,以检查其中是否包含组织/休眠/ cfg /中Configuration.class