2013-10-17 179 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