高手求救:Spring集成问题
spring配置文件
<beans>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@127.0.0.1:1521:ORCL">
</property>
<property name="username" value="fund"></property>
<property name="password" value="fund"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>edu/xust/fund/orm/Proposerinfo.hbm.xml</value>
<value>edu/xust/fund/orm/Iteminfo.hbm.xml</value>
<value>edu/xust/fund/orm/Userinfo.hbm.xml</value>
<value>edu/xust/fund/orm/Bugdetoutlay.hbm.xml</value>
<value>edu/xust/fund/orm/College.hbm.xml</value>
<value>edu/xust/fund/orm/Distribute.hbm.xml</value>
<value>edu/xust/fund/orm/Sort.hbm.xml</value>
<value>edu/xust/fund/orm/Declaretime.hbm.xml</value>
<value>edu/xust/fund/orm/Experinfo.hbm.xml</value>
</list>
</property>
</bean>
<bean id="userinfoDao" class="edu.xust.fund.service.UserinfoDao">
<property name="dataSource">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean name="login" class="edu.xust.fund.action.LoginAction">
<property name="userinfoDao">
<ref bean="userinfoDao"/>
</property>
</bean>
</beans>
急……谢谢!

解决方案 »

  1.   

    错误:
    严重: StandardWrapper.Throwable
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userinfoDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [edu.xust.fund.service.UserinfoDao]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [edu.xust.fund.service.UserinfoDao]: Bean property 'dataSource' 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:793)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:645)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1127)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:291)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:189)
    at org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:82)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    2009-5-10 10:10:20 org.apache.catalina.core.StandardContext loadOnStartup
      

  2.   

    userinfoDao要在action中set和get一下
      

  3.   

    这个在Action中有,已经有set和get方法
      

  4.   

    该不会是数据类型不一致吧!
    dao中声明的dataSource的类型与注入的类型不一致了吧
      

  5.   

    Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [edu.xust.fund.service.UserinfoDao]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 上面错误中Bean property 'dataSource' is not writable or has an invalid setter method
    应该很明显了
      

  6.   

    userinfoDao要有get,set方法
    另外你注入的内容错误了
    <bean id="userinfoDao" class="edu.xust.fund.service.UserinfoDao"> 
    <property name="dataSource"> 
    <ref bean="sessionFactory"/> 
    </property> 
    --------------------------------------------------------------------
    改成
    <bean id="userinfoDao" class="edu.xust.fund.service.UserinfoDao"> 
    <property name="dataSource"> 
    <ref bean="dataSource"/> 
    </property> 
    或者
    <bean id="userinfoDao" class="edu.xust.fund.service.UserinfoDao"> 
    <property name="sessionFactory"> 
    <ref bean="sessionFactory"/> 
    </property> 
    对应的get,set也需要改变
      

  7.   

    不知道你在dao中引用的DataSource是哪个包的!
      

  8.   

    找楼上解决了,太谢谢你了!可是我以前在学习的时候,做的系统,代码就是那么写的,没有任何错误,而且struts、hibernate和spring一次合成,不会出错,过了几个月用就成了这样,真搞不懂,在struts中集成spring的时候,以前是在struts中写如下代码
    <plug-in
    className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation"
    value="/WEB-INF/applicationContext.xml" />
    </plug-in>
    现在不行了,得在web.xml中配置。
    能不能告诉我这些都是什么原因造成的?谢谢!
      

  9.   

    改成了这样好了
    <bean id="userinfoDao" class="edu.xust.fund.service.UserinfoDao">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>