2012-12-02 86 views
0

這裏是我的web.xml和applicationContext.xml的誤差名創建豆 'SessionFactory的'

<?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:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/tx 
     http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
     http://www.springframework.org/schema/aop 
     http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> 


    <bean id="sessionFactory" scope="singleton" 
     class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
     <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> 
    </bean> 

    <!-- Springs Hibernate Transaction Manager --> 
    <bean id ="transactionManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager"> 
     <property name = "sessionFactory" ref = "sessionFactory"/> 
    </bean> 

    <tx:annotation-driven/> 

    <!-- Inject my business services class to the action --> 
    <bean id="services" class ="services.Services" scope ="singleton"> 
     <property name = "sessionFactory" ref = "sessionFactory"/> 
    </bean> 



</beans> 

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    version="3.0"> 
    <display-name>Events</display-name> 
    <welcome-file-list> 
     <welcome-file>index.html</welcome-file> 
     <welcome-file>index.htm</welcome-file> 
     <welcome-file>index.jsp</welcome-file> 
     <welcome-file>default.html</welcome-file> 
     <welcome-file>default.htm</welcome-file> 
     <welcome-file>default.jsp</welcome-file> 
    </welcome-file-list> 


    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 


    <!-- Sitemesh (needs to be before struts) --> 
    <filter> 
     <filter-name>sitemesh</filter-name> 
     <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> 
    </filter> 
    <filter-mapping> 
     <filter-name>sitemesh</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <!-- Struts2 config (needs to be after sitemesh) --> 
    <filter> 
     <filter-name>struts2</filter-name> 
     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 
    </filter> 
    <filter-mapping> 
     <filter-name>struts2</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 


</web-app> 

當起tomcat這個錯誤出現了對測井公司

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) 
    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:587) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556) 
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration 
    at java.lang.Class.getDeclaredConstructors0(Native Method) 
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) 
    at java.lang.Class.getConstructor0(Unknown Source) 
    at java.lang.Class.getDeclaredConstructor(Unknown Source) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990) 
    ... 23 more 
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) 
    ... 29 more 
+2

的錯誤是不言自明:'NoClassDefFoundError的:組織/休眠/ cfg中/ Configuration'。確保你的類路徑上有hibernate。 –

+0

我把我的配置文件放在src文件夾中。 – user962206

+0

這不是關於配置文件,而是關於jar文件。 –

回答

1

根據我讀過的評論看你的hibernate-core jar沒有被Eclipse注意到。重建你的類路徑。

0

這就是一些很好的建議。我失蹤了Hibernate的核心罐是的Y它沒有得到會話工廠啓動......下面

是我參考的pom.xml。

http://maven.apache.org/xsd/maven-4.0.0.xsd「> 4.0.0 HibernateReverseEng HibernateReverseEng 0.0.1-SNAPSHOT SRC 行家編譯-插件 3.3 1.8 1.8 JBoss的庫 http://repository.jboss.com/maven2/

<properties> 
    <springframework.version>4.0.6.RELEASE</springframework.version> 
</properties> 

<dependencies> 

    <!-- Spring Core and framework dependencies --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>${springframework.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${springframework.version}</version> 
    </dependency> 

    <!-- JUnit testing framework --> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 

    <!-- Spring framework --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring</artifactId> 
     <version>2.5.6</version> 
    </dependency> 

    <!-- Spring AOP dependency --> 
    <dependency> 
     <groupId>cglib</groupId> 
     <artifactId>cglib</artifactId> 
     <version>2.2</version> 
    </dependency> 

    <!-- MySQL database driver --> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.9</version> 
    </dependency> 

    <!-- Hibernate framework --> 
    <dependency> 
     <groupId>hibernate</groupId> 
     <artifactId>hibernate3</artifactId> 
     <version>3.2.3.GA</version> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>3.3.0.GA</version> 
    </dependency> 


    <!-- Hibernate annotation --> 
    <dependency> 
     <groupId>hibernate-annotations</groupId> 
     <artifactId>hibernate-annotations</artifactId> 
     <version>3.3.0.GA</version> 
    </dependency> 

    <dependency> 
     <groupId>hibernate-commons-annotations</groupId> 
     <artifactId>hibernate-commons-annotations</artifactId> 
     <version>3.0.0.GA</version> 
    </dependency> 

    <!-- Hibernate library dependecy start --> 
    <dependency> 
     <groupId>dom4j</groupId> 
     <artifactId>dom4j</artifactId> 
     <version>1.6.1</version> 
    </dependency> 

    <dependency> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
     <version>1.1.1</version> 
    </dependency> 

    <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
     <version>3.2.1</version> 
    </dependency> 

    <dependency> 
     <groupId>antlr</groupId> 
     <artifactId>antlr</artifactId> 
     <version>2.7.7</version> 
    </dependency> 
    <!-- Hibernate library dependecy end --> 

    <dependency> 
     <groupId>commons-dbcp</groupId> 
     <artifactId>commons-dbcp</artifactId> 
     <version>1.4</version> 
    </dependency> 

    <dependency> 
     <groupId>org.eclipse.persistence</groupId> 
     <artifactId>javax.persistence</artifactId> 
     <version>2.0.0</version> 
    </dependency> 

</dependencies> 

相關問題