在applicationContext.xml中配置了和Hibernate的集成,没有问题;现在想在spring配置中加入事务管理,于是找了段代码 
<!-- 定义事务管理 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean> <!-- 配置事务拦截器 -->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean> <bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>SshDAO</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
但是插入这段代码后,启动tomcat的时候就报错,说:
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/login' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0 implementing org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.ssh.hibernate.SSH.SshDAO] for property 'dao'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0 implementing org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.ssh.hibernate.SSH.SshDAO] for property 'dao': no matching editors or conversion strategy found

我使用的是MyEclipse7.1,tomcat 6.0.20 不知道有没有解决办法,多谢了!!!

解决方案 »

  1.   

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/login' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed
      

  2.   

    beanfactory没初始化成功,另外,你的配置文件没给全,咋看得出来?
      

  3.   

    TypeMismatchException类型不匹配
    最好是把其它的也弄出来看看
      

  4.   

    哥哥,好像事务不是这样用的吧,应该是把事务定义到业务逻辑接口上,你又没有用aop,弄啥拦截器啊,不明白
      

  5.   

    这个错误不是这段代码,是你配置管理action跳转的那一段
      

  6.   

    Error creating bean with name '/login' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed
      

  7.   

    <bean
            class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
            <property name="beanNames">
                <list>
                    <value>SshDAO</value>
                </list>
            </property>
            <property name="interceptorNames">
                <list>
                    <value>transactionInterceptor</value>
                </list>
            </property>
        </bean>   可能是这段有问题,看不到其他配置,不知道这个和其他的关系。
      

  8.   


    <bean
            class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
            <property name="beanNames">
                <list>
                    <value>SshDAO</value>            </list>
            </property>
            <property name="interceptorNames">
                <list>
                    <value>transactionInterceptor</value>
                </list>
            </property>
        </bean>加上这段就有问题了,可是我看到书上就是这么写的啊,以后要加新的dao需要事务管理的时候,只要在标红的地方加新的dao就可以了。我觉得错误好像是这个:Failed to convert property value of type [$Proxy0 implementing org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.ssh.hibernate.SSH.SshDAO] for property 'dao'
    但是不知道怎么改
      

  9.   

     加入<property name="proxyTargetClass" value="true"/>
      

  10.   

      <!-- 配置事务拦截器 -->
        <bean id="transactionInterceptor"
            class="org.springframework.transaction.interceptor.TransactionInterceptor">
            <property name="transactionManager">
                <ref bean="transactionManager" />
            </property>
            <property name="proxyTargetClass" value="true"/>
            <property name="transactionAttributes">
                <props>
                    <prop key="add*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>