org.springframework.les haricots.usine.BeanCreationException: Erreur lors de la création de haricots avec le nom "sessionFactory" défini dans le chemin de classe de ressource [jlcindia.xml]

Quand je lance mon application, j'obtiens l'exception ci-dessous:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in class path resource [jlcindia.xml]:
Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException:
Could not parse mapping document from invalid mapping
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.jlcindia.spring.hibernate.LAB27.main(LAB27.java:13)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:502)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:677)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 12 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 19; Document is invalid: no grammar found.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)
... 16 more

C'est le jlcindia.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/jlcindiadb"/> 
<property name="username" value="root"/>
<property name="password" value="santhosh"/>
</bean> 
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" p:dataSource-ref="dataSource"> 
<property name="mappingResources">
<list> 
<value>com/jlcindia/spring/hibernate/Customer.hbm.xml</value>
</list>
</property> 
<property name="hibernateProperties">
<map> 
<entry key="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<entry key="hibernate.show_sql" value="true"/> 
<entry key="hibernate.hbm2ddl.auto" value="create"/> 
</map> 
</property> 
</bean> 
<bean id="hibernateTemp" class="org.springframework.orm.hibernate3.HibernateTemplate" autowire="constructor"/> 
<bean id="cdao" class="com.jlcindia.spring.hibernate.HibernateCustomerDAO"/> 
<bean id="cs" class="com.jlcindia.spring.hibernate.CustomerServiceImpl"/>
</beans>

Et la classe principale:

public class LAB27 { 
public static void main(String[] args) {
ApplicationContext ctx=new ClassPathXmlApplicationContext("jlcindia.xml"); 
CustomerService cs=(CustomerService)ctx.getBean("cs"); 
//1. addCustomer
CustomerTO cto=new CustomerTO("san","[email protected]",98989,"bangalore");
cs.addCustomer(cto);
} 
}

Et la Customer.hbm.xml

//Customer.hbm.xml
<hibernate-mapping package="com.jlcindia.spring.hibernate">
<class name="Customer" table="Customer" lazy="false">
<id name="cid" column="cid" type="int">
<generator class="increment"/>
</id>
<property name="cname"/>
<property name="email" />
<property name="phone" />
<property name="city"/>
</class>
</hibernate-mapping>

Toute aide est grandement appréciée

  • Vous devez montrer votre jlcindia.xml fichier et également les modifier à votre question pour en faire un diable de beaucoup plus facile à lire!
  • j'ai placé jlcindia.xml et la méthode main
  • Qu'advient-il si vous ajoutez <?xml version="1.0" encoding="UTF-8"?> pour le commencement absolu du fichier?
  • Elle donne le même message d'erreur.
  • s'il vous plaît montrer votre Customer.hbm.xml l'exception dit que c'est InvalidMappingException: Could not parse mapping document from invalid
  • Salut, j'ai placé Customer.hbm.xml fichier
  • Avez-vous le //Customer.hbm.xml dans le fichier xml sur votre première ligne?
  • L'erreur a été corrigé. Cette erreur se produit en raison de hibernate3.jar pour cela j'ai téléchargé le nouveau hibernate3.jar et je l'ai placé à l'intérieur du chemin de génération, il fonctionne. Merci pour tout u donner une suggestion .

InformationsquelleAutor user3522207 | 2014-05-30