qq_34905541
qq_34905541
采纳率0%
2017-03-09 07:45

关于springmvc+spring+hibernate用java类测试的问题

15

图片说明本人分了五个spring的xml,分别用来管理不同层的业务;现在想用java类测试,但是报错了;求各位大神看看

以下是报错信息
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDao' defined in file [D:\mobile\Mobile.Store.WebApp\WebRoot\WEB-INF\classes\com\mobilestore\configs\spring-dao.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:\mobile\Mobile.Store.WebApp\WebRoot\WEB-INF\classes\com\mobilestore\configs\spring-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'MstoredataSource' of bean class [org.springframework.orm.hibernate4.LocalSessionFactoryBean]: Bean property 'MstoredataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1391)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.mobilestore.test.BeanTest.main(BeanTest.java:17)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\mobile\Mobile.Store.WebApp\WebRoot\WEB-INF\classes\com\mobilestore\configs\spring-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'MstoredataSource' of bean class [org.springframework.orm.hibernate4.LocalSessionFactoryBean]: Bean property 'MstoredataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1427)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
... 15 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'MstoredataSource' of bean class [org.springframework.orm.hibernate4.LocalSessionFactoryBean]: Bean property 'MstoredataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1044)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:904)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1424)
... 23 more

spring-dao.xml的代码
            <?xml version="1.0" encoding="UTF-8"?>

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.xsd">

<bean id="personDao" class="com.mobilestore.dao.impl.PersonDaoImpl">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>


spring-service.xml

<?xml version="1.0" encoding="UTF-8"?>
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.xsd">

<bean id="PersonServiceTarget" class="com.mobilestore.service.impl.PersonServiceImpl">  
    <property name="personDao" ref="personDao"/>  
</bean>  

<!-- 此处为代理 -->  
<bean name="PersonService" parent="transactionProxy">  
    <property name="target" ref="PersonServiceTarget"/>  
</bean>   

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • qq455276333 在路上的JavaCoder-尹骑 4年前
     Bean property 'MstoredataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    

    MstoredataSource没有setter方法

    点赞 评论 复制链接分享
  • lsttoy 乐扣老师lekkoliu 4年前

    Error creating bean with name 'personDao'
    没有被配置到bean扫描中,出错了。

    点赞 评论 复制链接分享
  • xiaoYiLuo520 MR-yiLuo 4年前

    Error creating bean with name 'personDao' defined in file [D:\mobile\Mobile.Store.WebApp\WebRoot\WEB-INF\classes\com\mobilestore\configs\spring-dao.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory

    图片说明这处有问题

    点赞 评论 复制链接分享

相关推荐