整合SH遇见错误 org.springframework.beans.factory.BeanCreationException,详细代码如下

GuominJin 2018-03-04 05:31:39
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [config/bean-base.xml]: Cannot resolve reference to bean 'sessionfactory' while setting bean property 'sessionfactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionfactory' defined in class path resource [config/bean-base.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: class cn.pzhu.usermanger.pojo.User.User not found while looking for property: uId
这个错误搞得我脑壳都大了
web.xml

<!-- spring的相关配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/config/bean-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

bean.xml

<?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">

<!-- 配置dao -->
<bean id="userDao" class="cn.pzhu.usermanger.dao.UserDao" p:sessionfactory-ref="sessionfactory"></bean>
<!-- 配置service -->
<bean id="userService" class="cn.pzhu.usermanger.service.UserService" p:userDao-ref="userDao"></bean>

<!-- 将Hibernate中的连接数据库的相关信息配置到Spring中 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="acquireIncrement" value="2"></property>
<property name="maxPoolSize" value="100"></property>
<property name="minPoolSize" value="2"></property>
<property name="maxStatements" value="100"></property>
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql:///springtest1"></property>
<property name="user" value="root"></property>
<property name="password" value="0000"></property>
</bean>

<!-- spring hibernate整合的关键是sessionfactory的创建问题 -->
<bean id="sessionfactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocations" value="classpath:config/hibernate.cfg.xml"></property>
</bean>

<!-- 配置事务 -->
<bean id="txManger" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource" ref="dataSource"></property>
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 配置事务增强 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" read-only="false"/>
</tx:attributes>
</tx:advice>

<!--配置aop -->
<aop:config>
<aop:pointcut expression="(execution (* cn.pzhu.usermanger.service.*.*(..)))" id="pt"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pt"/>
</aop:config>

</beans>

Hibernate就不贴了
User.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cn.pzhu.usermanger.pojo.User">
<class name="User" table="t_user">
<id name="uId">
<generator class="native">
</generator>
</id>
<!--配置的是普通的属性 -->
<property name="uName"></property>
<property name="uPassword"></property>
</class>
</hibernate-mapping>

求大神解答!!!
求大神解答!!!
求大神解答!!!
求大神解答!!!
求大神解答!!!
求大神解答!!!
求大神解答!!!
求大神解答!!!
求大神解答!!!
求大神解答!!!
求大神解答!!!
求大神解答!!!

...全文
340 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_40066981 2018-03-04
  • 打赏
  • 举报
回复
我感觉是你那个web.xml文件是不是有问题?一般不都是<param-value>classpath:开头啊

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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