ssh创建bean失败

qq_35338656 2017-07-12 04:34:27
我的一直显示找不到User类 路径啥的没错 错误这样子:
16:22:16,137  WARN XmlWebApplicationContext:546 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [bean.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: class com.oa.domain.User not found while looking for property: id
16:22:16,140 ERROR ContextLoader:353 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [bean.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: class com.oa.domain.User not found while looking for property: id
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)

bean的配置是这样:
<?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:context="http://www.springframework.org/schema/context"
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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

<!-- 配置c3p0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 注入属性值 -->
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql:///oa"></property>
<property name="user" value="root"></property>
<property name="password" value="YiXijun0327"></property>
</bean>

<!-- sessionFactory创建交给spring管理 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- 因为在hibernate核心配置文件中,没有数据库配置,数据库配置在spring里面配置,注入dataSource -->
<property name="dataSource" ref="dataSource"></property>

<!-- 指定使用hibernate核心配置文件 -->
<property name="configLocations" value="classpath:hibernate.cfg.xml"></property>
</bean>

<!-- 第一步 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<!--注入sessionFactory-->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 第二步 开启事务注解 -->
<tx:annotation-driven transaction-manager="transactionManager"/>

<!-- 配置action的对象 -->
<bean id="userAction" class="com.oa.action.UserAction" scope="prototype">
<!-- 注入service -->
<property name="userService" ref="userServiceImpl"></property>
</bean>

<!-- 创建service对象 -->
<bean id="userServiceImpl" class="com.oa.service.impl.UserServiceImpl">
<!-- 注入dao
接口 = 实现类对象
-->
<property name="userDao" ref="userDaoImpl"></property>
</bean>

<!-- 创建实现类对象 -->
<bean id="userDaoImpl" class="com.oa.dao.impl.UserDaoImpl">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>

<!-- 创建hibernateTemplate对象 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<!-- 注入sessionFactory -->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
...全文
470 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
业余草 2017-07-13
  • 打赏
  • 举报
回复
创建sessionfactory 失败。 大概的意思是说你的user类中没有主键。id不是主键或者不是自增主键之类的。 www.xttblog.com www.codedq.net 业余草 CODE大全 欢迎关注我的个人微信公众号:业余草(yyucao)!
qq_35942223 2017-07-12
  • 打赏
  • 举报
回复
看一下你user类
qq_35338656 2017-07-12
  • 打赏
  • 举报
回复
这可咋办啊 各位大佬。。

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧