请教各位师哥,有经验的前辈(spring集成hibernate)

youc 发布于 2012/03/08 21:19
阅读 8K+
收藏 0
我的错误信息 Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userdaoimpl' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: class cn.micblog.domain.UserBean not found while looking for property: user_id at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880) at cn.micblog.TestDao.UserDAOTest.main(UserDAOTest.java:49) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: class cn.micblog.domain.UserBean not found while looking for property: user_id at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:1029) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:977) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472) ... 10 more Caused by: org.hibernate.MappingException: class cn.micblog.domain.UserBean not found while looking for property: user_id at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:232) at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:302) at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:423) at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:356) at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295) at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166) at org.hibernate.cfg.Configuration.add(Configuration.java:716) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:551) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:631) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) ... 22 more Caused by: java.lang.ClassNotFoundException: cn.micblog.domain.UserBean at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192) at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:228) ... 33 more spring配置文件 cn/micblog/model/UserBean.hbm.xml cn/micblog/model/MessageBean.hbm.xml cn/micblog/model/FollowBean.hbm.xml cn/micblog/model/LoginBean.hbm.xml cn/micblog/model/ProfileBean.hbm.xml cn/micblog/model/ManageProfileBean.hbm.xml cn/micblog/model/ManageUserBean.hbm.xml hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.hbm2ddl.auto=update hibernate.show_sql=true hibernate.formate_sql=false test类 package cn.micblog.TestDao; import java.util.Date; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import cn.micblog.dao.impl.UserDaoImpl; import cn.micblog.exception.DAOException; import cn.micblog.model.FollowBean; import cn.micblog.model.MessageBean; import cn.micblog.model.ProfileBean; import cn.micblog.model.UserBean; public class UserDAOTest { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub UserDaoImpl dao = new UserDaoImpl(); UserBean bean = new UserBean(); MessageBean bean2 = new MessageBean(); ProfileBean bean3 = new ProfileBean(); FollowBean bean4 = new FollowBean(); bean.setName("小麦芽"); bean.setActnumber("youc"); bean.setR_date(new Date()); bean2.setCreateDate(new Date()); bean2.setContents("第一条消息"); bean2.setUser(bean); bean3.setNickname("小麦芽"); bean3.setOldpaswd("mima1"); bean3.setNewpaswd("mima2"); bean3.setConfirmpaswd("mima2"); bean3.setUser(bean); bean4.setMessage_id(002); bean4.setNickname("小麦芽"); bean4.setUser(bean); // Spring 独立启动 ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); UserDaoImpl userDaoImpl = (UserDaoImpl) context.getBean("userdaoimpl"); try { UserBean user = (UserBean) userDaoImpl.selectByactnumber("youc"); } catch (DAOException e) { e.printStackTrace(); } System.out.println(bean.getActnumber()); // // Hibernate 启动 // Configuration config = new Configuration().configure(); // SessionFactory sessionFactory = config.buildSessionFactory(); // // Session session = sessionFactory.openSession(); // // UserBean user = new UserBean(); // session.saveOrUpdate(user); // session.save(user); } }
加载中
0
川口人
川口人

userdaoimpl' defined in class path resource [beans.xml]: Initialization of bean failed

bean初始化有问题啊  是不是什么东西没给他传  还是父类 接口需要的东西没具备 还是xml中该定义的没定义?

user_id 没找到

0
youc
youc

引用来自“门徒”的答案

userdaoimpl' defined in class path resource [beans.xml]: Initialization of bean failed

bean初始化有问题啊  是不是什么东西没给他传  还是父类 接口需要的东西没具备 还是xml中该定义的没定义?

user_id 没找到

该传的 我都传了啊

xml中定义的是没问题

orm没集成spring前我的表都是能创建的 测试类通过了 现在继承spring找不到beans.xml 哎

0
卿臣
卿臣

Invocation of init method failed; nested exception is org.hibernate.MappingException: class cn.micblog.domain.UserBean not found while looking for property: user_id

user表中的字段“user_id”在UserBean中没有正确映射关系。

0
黄龍
黄龍

你敢不敢格式化一下代码?

bean.xml也发出来!

0
youc
youc
这个问题已解决,谢谢前辈们的支持,感激,错误原因是我 model包刚开始叫的domain,这样一改 Hibernate映射文件不能自动更改,所以Hibernate映射文件找不到 谢谢
jeffsui
jeffsui
解决了就好。
0
李序锴
李序锴

还能再乱一点吗?眼睛都快看瞎了...

返回顶部
顶部