org.springframework.beans.factory.BeanCreationException: Error creating bean

yuhongzhan 2010-12-11 11:01:02
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
...全文
10333 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
在路上___ 2012-12-02
  • 打赏
  • 举报
回复
贴主,我也遇到了这个问题困扰了好几天,不知道是怎么会是,可以帮助我一下吗, 61762897 我的QQ
yuhongzhan 2010-12-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wzju64676266 的回复:]

hibernate.cfg.xml 这个代码贴一下,还有sqlmap文件
[/Quote]关注下咯
yuhongzhan 2010-12-12
  • 打赏
  • 举报
回复
没有sqlmap文件直接用个sql-connectJava包就可以连接mysql
yuhongzhan 2010-12-12
  • 打赏
  • 举报
回复
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>
wzju64676266 2010-12-12
  • 打赏
  • 举报
回复
hibernate.cfg.xml 这个代码贴一下,还有sqlmap文件
yuhongzhan 2010-12-12
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 shaosijun2004 的回复:]

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这个吧
……
[/Quote]那个hibernate.cfg.xml贴在上面了,帮我看下咯~!谢谢
yuhongzhan 2010-12-12
  • 打赏
  • 举报
回复
我仔细找了一下原来是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管理,所以报错~!
wzju64676266 2010-12-12
  • 打赏
  • 举报
回复
com/demo/model/Person.hbm.xml 文件干嘛不贴一下问题就在这里了
Jlins 2010-12-12
  • 打赏
  • 举报
回复
Person.hbm.xml 这个配置文件 配置的persion实体对应的数据库类型检查下 特别是 int的类型
Jlins 2010-12-12
  • 打赏
  • 举报
回复
An association from the table t_person refers to an unmapped class: int

很明显一个表字段映射错误了吧
yuhongzhan 2010-12-12
  • 打赏
  • 举报
回复
在线等答案,好郁闷啊困扰我一整天了
shaosijun2004 2010-12-12
  • 打赏
  • 举报
回复
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这个吧
shaosijun2004 2010-12-12
  • 打赏
  • 举报
回复
Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'

不是说 你配置 通知器的 时候 没 注入 事务管理器么?
yuhongzhan 2010-12-11
  • 打赏
  • 举报
回复
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>
yuhongzhan 2010-12-11
  • 打赏
  • 举报
回复
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>
yuhongzhan 2010-12-11
  • 打赏
  • 举报
回复
包没有冲突

67,515

社区成员

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

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