Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
org.springframework.beans.factory.BeanCreationException创建名为';sessionFactory';在ServletContext中定义_Spring_Hibernate_Jakarta Ee_Spring Mvc_Hibernate Mapping - Fatal编程技术网

org.springframework.beans.factory.BeanCreationException创建名为';sessionFactory';在ServletContext中定义

org.springframework.beans.factory.BeanCreationException创建名为';sessionFactory';在ServletContext中定义,spring,hibernate,jakarta-ee,spring-mvc,hibernate-mapping,Spring,Hibernate,Jakarta Ee,Spring Mvc,Hibernate Mapping,我尝试部署应用程序,但是控制台显示了这个错误,我不熟悉SpringMVC和Hibernate3。这是我的第一个项目 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of ini

我尝试部署应用程序,但是控制台显示了这个错误,我不熟悉SpringMVC和Hibernate3。这是我的第一个项目

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: component class not found: com.GestionEtudiant.model.EtudiantId
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:684)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701)
        at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204)
        at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199)
        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: org.hibernate.MappingException: component class not found: com.GestionEtudiant.model.EtudiantId
        at org.hibernate.mapping.Component.getComponentClass(Component.java:104)
        at org.hibernate.tuple.component.PojoComponentTuplizer.buildGetter(PojoComponentTuplizer.java:133)
        at org.hibernate.tuple.component.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:43)
        at org.hibernate.tuple.component.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:38)
        at org.hibernate.tuple.component.ComponentEntityModeToTuplizerMapping.<init>(ComponentEntityModeToTuplizerMapping.java:52)
        at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:50)
        at org.hibernate.mapping.Component.buildType(Component.java:152)
        at org.hibernate.mapping.Component.getType(Component.java:145)
        at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
        at org.hibernate.mapping.RootClass.validate(RootClass.java:193)
        at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745)
        at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
        ... 19 more
    Caused by: java.lang.ClassNotFoundException: com.GestionEtudiant.model.EtudiantId
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
        at org.hibernate.mapping.Component.getComponentClass(Component.java:101)
        ... 35 more

com.GestionEtudiant.model.etudiandi
需要位于类路径中。它是否部署在war文件中?

如果您在etudiandi.hbm.xml中定义了com.GestionEtudiant.model.etudiandi的映射 将其添加到“mappingResources”中,如下所示

 <property name="mappingResources">
        <list>
          ...
           <value>com/GestionEtudiant/model/EtudiantId.hbm.xml</value>
          ...

试着清理你的日食,对我来说很有效


转到cmd并执行eclipse-clean查看堆栈跟踪中的最终原因:这是一个标准类路径问题。用XML配置再次检查类名;它们区分大小写。类etudiandi是使用hibernate Toolsys从数据库自动生成的,但我没有etudiandi.hbm.xml,因为它只用于person和etudiant类之间的关系。问题是“因为缺少此关系”。自动生成的etudiandi.class是否使用anotation?你能发布那个类吗?也许我还有一个问题是关联引用未映射的类:com.GestionEtudiant.model.UserWorked也为我工作。谢谢@sagar
<?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:p="http://www.springframework.org/schema/p"
    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-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <!-- Action Handling -->
    <!-- BeanNameUrlHandlerMapping This configuration is optional because BeanNameUrlHandlerMapping 
        is the default handler. In case no handler mapping is found in the web application 
        context, SpringMVC will create an instance of BeanNameUrlHandlerMapping. -->
    <bean name="beanNameUrlHandlerMapping"
        class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />

    <!-- SimpleUrlHandlerMapping The BeanNameUrlHandlerMapping class does not 
        support wildcards to resolve a request URL to a bean name. Configuration 
        can be simplified with Apache Ant–style wildcard path mapping with the SimpleUrlHandlerMapping. 
        <bean name="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
        <property name="mappings"> <props> <prop key="/*.html"></prop> </props> </property> 
        </bean> -->
    <!-- ControllerClassNameHandlerMapping <bean name="controllerClassNameHandlerMapping" 
        class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> -->
    <!-- end of Action Handling -->


    <!-- View Handler -->
    <!-- InternalResourceViewResolver The InternalResourceViewResolver class 
        can determine the physical view in the web application archive given the 
        logical view name. -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
    <!-- ResourceBundleViewResolver It allows the logical view name to physical 
        resource mapping to be configured in externalized properties or resource 
        bundle files. <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver"> 
        <property name="basename" value=""/> </bean> -->
    <!-- XmlViewResolver To use an XML-based view resolver, configuration information 
        should be moved in XML files from the properties file. This view configuration 
        file should be located in the WEB-INF folder and is called views.xml by default. 
        <bean id="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver"/> -->
    <!-- end of View Handler -->


    <!-- Page Controller -->

    <bean name="/Comptes.html" class="com.affectation.controller.CompteController"
        p:compteService="compteService" p:compteService-ref="compteService" />
<!-- end of Page Controller -->


    <!-- <bean id="springUtilInitializer" class="com.affectation.controller.SpringApplicationContextHolder" 
        lazy-init="false" /> -->
</beans>
<?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:p="http://www.springframework.org/schema/p"
    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-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <!-- Action Handling -->
    <!-- BeanNameUrlHandlerMapping This configuration is optional because BeanNameUrlHandlerMapping 
        is the default handler. In case no handler mapping is found in the web application 
        context, SpringMVC will create an instance of BeanNameUrlHandlerMapping. -->
    <bean name="beanNameUrlHandlerMapping"
        class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />

    <!-- SimpleUrlHandlerMapping The BeanNameUrlHandlerMapping class does not 
        support wildcards to resolve a request URL to a bean name. Configuration 
        can be simplified with Apache Ant–style wildcard path mapping with the SimpleUrlHandlerMapping. 
        <bean name="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
        <property name="mappings"> <props> <prop key="/*.html"></prop> </props> </property> 
        </bean> -->
    <!-- ControllerClassNameHandlerMapping <bean name="controllerClassNameHandlerMapping" 
        class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> -->
    <!-- end of Action Handling -->


    <!-- View Handler -->
    <!-- InternalResourceViewResolver The InternalResourceViewResolver class 
        can determine the physical view in the web application archive given the 
        logical view name. -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
    <!-- ResourceBundleViewResolver It allows the logical view name to physical 
        resource mapping to be configured in externalized properties or resource 
        bundle files. <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver"> 
        <property name="basename" value=""/> </bean> -->
    <!-- XmlViewResolver To use an XML-based view resolver, configuration information 
        should be moved in XML files from the properties file. This view configuration 
        file should be located in the WEB-INF folder and is called views.xml by default. 
        <bean id="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver"/> -->
    <!-- end of View Handler -->


    <!-- Page Controller -->

    <bean name="/Comptes.html" class="com.affectation.controller.CompteController"
        p:compteService="compteService" p:compteService-ref="compteService" />
<!-- end of Page Controller -->


    <!-- <bean id="springUtilInitializer" class="com.affectation.controller.SpringApplicationContextHolder" 
        lazy-init="false" /> -->
</beans>
package com.GestionEtudiant.model;


    public class EtudiantId implements java.io.Serializable {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        private int idPersonne;
        private int idEtudiant;

        public EtudiantId() {
        }

        public EtudiantId(int idPersonne, int idEtudiant) {
            this.idPersonne = idPersonne;
            this.idEtudiant = idEtudiant;
        }

        public int getIdPersonne() {
            return this.idPersonne;
        }

        public void setIdPersonne(int idPersonne) {
            this.idPersonne = idPersonne;
        }

        public int getIdEtudiant() {
            return this.idEtudiant;
        }

        public void setIdEtudiant(int idEtudiant) {
            this.idEtudiant = idEtudiant;
        }

        public boolean equals(Object other) {
            if ((this == other))
                return true;
            if ((other == null))
                return false;
            if (!(other instanceof EtudiantId))
                return false;
            EtudiantId castOther = (EtudiantId) other;

            return (this.getIdPersonne() == castOther.getIdPersonne())
                    && (this.getIdEtudiant() == castOther.getIdEtudiant());
        }

        public int hashCode() {
            int result = 17;

            result = 37 * result + this.getIdPersonne();
            result = 37 * result + this.getIdEtudiant();
            return result;
        }

    }
 <property name="mappingResources">
        <list>
          ...
           <value>com/GestionEtudiant/model/EtudiantId.hbm.xml</value>
          ...
<bean id="sessionFactory"
     <property name="packagesToScan" value="com.GestionEtudiant.model" />