首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

org.springframework.beans.factory.BeanCreationException: Error creating bean,该怎么

2013-09-11 
org.springframework.beans.factory.BeanCreationException: Error creating beanorg.springframework.bea

org.springframework.beans.factory.BeanCreationException: Error creating bean
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginService' defined in file [D:\Tomcat 5.5\webapps\Demo\WEB-INF\classes\applicationContext-actions.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [D:\Tomcat 5.5\webapps\Demo\WEB-INF\classes\applicationContext-common.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 file [D:\Tomcat 5.5\webapps\Demo\WEB-INF\classes\applicationContext-common.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table t_person refers to an unmapped class: int

[最优解释]
Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table t_person refers to an unmapped class: int
看错了,你的map貌似没加载成功,看看hibernate.cfg.xml这个吧
[其他解释]
com/demo/model/Person.hbm.xml   文件干嘛不贴一下问题就在这里了
[其他解释]
hibernate.cfg.xml  这个代码贴一下,还有sqlmap文件
[其他解释]
Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'

不是说 你配置 通知器的 时候 没 注入 事务管理器么?
[其他解释]
 An association from the table t_person refers to an unmapped class: int

很明显一个表字段映射错误了吧
[其他解释]
Person.hbm.xml 这个配置文件  配置的persion实体对应的数据库类型检查下  特别是 int的类型
[其他解释]
包没有冲突
[其他解释]
applicationContext-common.xml文件
<?xml version="1.0" encoding="UTF-8"?>

<!--
  - Application context definition for JPetStore's business layer.
  - Contains bean references to the transaction manager and to the DAOs in
  - dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation").
  -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


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

<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>           

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

<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>

<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut expression="execution(* com.struts2.service.*.*(..))" id="allManagerMethod"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
</aop:config>
</beans>

[其他解释]
applicationContext-actions.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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

<bean id="loginService" class="com.struts2.service.impl.LoginServiceImpl">
</bean>
<bean id="loginAction" class="com.struts2.action.LoginAction" scope="prototype">
<property name="loginService" ref="loginService"></property>
</bean>

</beans>

[其他解释]
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost/demo</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">mysql</property>


    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <mapping resource="com/demo/model/Person.hbm.xml"/>
  </session-factory>
</hibernate-configuration>
[其他解释]
没有sqlmap文件直接用个sql-connectJava包就可以连接mysql
[其他解释]

引用:
hibernate.cfg.xml  这个代码贴一下,还有sqlmap文件
关注下咯
[其他解释]
引用:
Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table t_person refers to an unmapped class: int
看错了,你的map貌似没加载成功,看看hibernate.cfg.xml这个吧
……
那个hibernate.cfg.xml贴在上面了,帮我看下咯~!谢谢
[其他解释]
在线等答案,好郁闷啊困扰我一整天了
[其他解释]
我仔细找了一下原来是com.struts2.service下的接口的实现方法没有继承HibernateDaoSupport,
并且我指定了<aop:config>
<aop:advisor pointcut="execution(* com.struts2.service.*.*(..))" advice-ref="txAdvice"/>
</aop:config>
下的所有接口参与事务
而我在bean中愣是 <bean id="loginService" class="com.struts2.service.impl.LoginServiceImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
</bean>
把业务逻辑交给Spring管理,所以报错~!
[其他解释]
该回复于2011-03-10 15:14:49被版主删除
[其他解释]
贴主,我也遇到了这个问题困扰了好几天,不知道是怎么会是,可以帮助我一下吗, 61762897 我的QQ

热点排行