
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.0.xsd"
default-autowire="byName" default-lazy-init="true">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>org.gjt.mm.mysql.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/rencaiwang</value>
</property>
<property name="username">
<value>rencaiwang</value>
</property>
<property name="password">
<value>rencaiwang</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<value>test/customer.hbm.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
</bean>
<!-- Transaction配置开始 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- Transaction配置结束 -->
<bean id="custManageServiceTarget" class="test.CustomerDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="customerDao"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref bean="custManageServiceTarget" />
</property>
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- Action及其Service被配置在applicationContext-XXX中 -->
<!-- 示例Customer action and dao -->
<bean id="customerAction" scope="prototype"
class="test.CustomerAction">
<property name="custDao">
<ref bean="customerDao" />
</property>
</bean>
</beans><property name="proxyTargetClass">
<value>true</value>
</property>如果没有这一段,动态注入的时候就会出现conversion错误。类似如下:
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy12 to required type
[com.brilliance.struts.service.impl.InvestServiceImpl] for property 'fundService'; nested exception is
java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy1] to required type
[com.brilliance.struts.service.impl.InvestServiceImpl] for property 'fundService': no matching editors or conversion strategy
found
本文介绍了Spring框架下整合Hibernate进行事务管理的配置方法,详细展示了配置文件applicationContext.xml的内容,并解释了如何通过设置proxyTargetClass解决动态代理时可能出现的类型转换错误。
335

被折叠的 条评论
为什么被折叠?



