hibernate加载hibernate.cfg.xml问题

snowwinner 2009-07-29 11:23:33
大虾们:
小弟在配置sessionFactory时出现了问题,他一直在提示不能把字符串赋值给
Configuration,请各位大侠帮忙!!!!!
...全文
235 2 打赏 收藏 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
snowwinner 2009-07-29
  • 打赏
  • 举报
回复
错误提示:::
2009-07-29 11:11:37,921 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1d63e39: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1d63e39]; startup date [Wed Jul 29 11:11:37 CST 2009]; root of context hierarchy
2009-07-29 11:11:38,125 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [applicationContext.xml]
2009-07-29 11:11:38,968 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@1d63e39]: org.springframework.beans.factory.support.DefaultListableBeanFactory@14520eb
2009-07-29 11:11:39,140 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@14520eb: defining beans [sessionFactory,transActionManager,txAdvice,org.springframework.aop.config.internalAutoProxyCreator,allImpl,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,logManagerImpl,userManagerImpl]; root of factory hierarchy
2009-07-29 11:11:39,453 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@14520eb: defining beans [sessionFactory,transActionManager,txAdvice,org.springframework.aop.config.internalAutoProxyCreator,allImpl,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,logManagerImpl,userManagerImpl]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.hibernate.cfg.Configuration] for property 'configuration'; nested exception is java.lang.IllegalArgumentException: Original must not be null
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:404)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:375)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:263)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:170)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:260)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:184)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:424)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.test.client.Client.main(Client.java:16)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.hibernate.cfg.Configuration] for property 'configuration'; nested exception is java.lang.IllegalArgumentException: Original must not be null
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1253)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:978)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:462)
... 14 more
Caused by: java.lang.IllegalArgumentException: Original must not be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.core.MethodParameter.<init>(MethodParameter.java:133)
at org.springframework.beans.BeanUtils.getWriteMethodParameter(BeanUtils.java:364)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
... 18 more
snowwinner 2009-07-29
  • 打赏
  • 举报
回复
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">

<!--第一步要把hibernate配置到spring中 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configuration">
<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="*" read-only="true"/>
</tx:attributes>
</tx:advice>

<!-- 哪些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allImpl" expression="execution(* com.test.dao.impl.*.*(..))"/>
<aop:advisor pointcut-ref="allImpl" advice-ref="txAdvice"/>
</aop:config>

<bean id="logManagerImpl" class="com.test.dao.impl.LogManagerImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="userManagerImpl" class="com.test.dao.impl.UserManagerImpl">
<property name="logm" ref="logManagerImpl"/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>

5,657

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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