SPring Hibernate 整合學習開發出現的錯誤

錯誤之前在幹什麼?

     在測試使用Hibernate框架的Dao組件的實現類,出現的錯誤!配置都正確,但是就是有錯誤!


log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).

log4j:WARN Please initialize the log4j system properly.
十一月 02, 2017 10:45:33 上午 org.hibernate.cfg.Environment <clinit>
信息: Hibernate 3.3.2.GA
十一月 02, 2017 10:45:33 上午 org.hibernate.cfg.Environment <clinit>
信息: hibernate.properties not found
十一月 02, 2017 10:45:33 上午 org.hibernate.cfg.Environment buildBytecodeProvider
信息: Bytecode provider name : javassist
十一月 02, 2017 10:45:33 上午 org.hibernate.cfg.Environment <clinit>
信息: using JDK 1.4 java.sql.Timestamp handling
十一月 02, 2017 10:45:33 上午 org.hibernate.cfg.Configuration configure
信息: configuring from url: file:/C:/Users/Administrator/Workspaces/MyEclipse%20Professional%202014/Spring02_2/WebRoot/WEB-INF/classes/hibernate.cfg.xml
十一月 02, 2017 10:45:33 上午 org.hibernate.cfg.Configuration addResource
信息: Reading mappings from resource : layers/domain.hbm.xml
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingNotFoundException: resource: layers/domain.hbm.xml not found

    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 layers.test.testUserdao.main(testUserdao.java:12)
Caused by: org.hibernate.MappingNotFoundException: resource: layers/domain.hbm.xml not found
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:610)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1491)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:642)
    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

錯誤原因是找不到 layers/domain.hbm.xml 資源

解決:原因是自己不知道在反向工程的時候,自己的包寫錯了,然後改了一下,但是框架給我在/Spring02_2/src/hibernate.cfg.xml的配置文件中自動生成了

<mapping resource="layers/domain.hbm.xml" />,實際上是我寫錯生成的,實際應該是

<mapping resource="layers/domain/User.hbm.xml" />  生成了前後這兩條,把前面的那條刪除就好了


在哪裏跌倒,在哪裏立個flag,大家請謹慎繞過!


其他錯誤請自行百度





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章