在配置多dataSource时启动项目报
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSourceRes' of bean class [org.springframework.orm.ibatis.SqlMapClientFactoryBean]: Bean property 'dataSourceRes' 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:1064)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:922)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:62)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1489)
... 81 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSourceRes' of bean class [org.springframework.orm.ibatis.SqlMapClientFactoryBean]: Bean property 'dataSourceRes' 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:1064)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:922)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:62)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1489)
... 81 more
<!-- 数据源1 -->
<bean id = "dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource" >
<property name="driverClass" value="${c3p0.driverClass}"></property>
<property name="jdbcUrl" value="${c3p0.url}"></property>
<property name="user" value="${c3p0.user}"></property>
<property name="password" value="${c3p0.password}"></property>
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"></property>
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property>
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"></property>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property>
<property name="minPoolSize" value="${c3p0.minPoolSize}"></property>
<property name="acquireRetryDelay" value="1000"></property>
<property name="acquireRetryAttempts" value="60"></property>
<property name="breakAfterAcquireFailure" value="false"></property>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation" value="classpath:sqlmap-config.xml"></property>
</bean>
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
<!-- 事物处理 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<!-- <property name="transactionManagerRes">
<ref bean="transactionManagerRes"/>
</property> -->
<property name="transactionAttributes">
<props>
<!--
表示类中的所有方法都要进行连接的关闭,和事务处理。 而且Spring还提供了多种事务处理方式,其中开发只使用下面这种。
PRPAGATION_REQUIRED:如果之前没有事务,则开始一个事务,如果之前有事务,则将当前操作合并到该事务中。
PRPAGATION_REQUIRED_NEW:无论之前是否有事务,都开始一个新的事务。
PRPAGATION_REQUIRED_NEVER:不支持事务,使用自动提交。
-->
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- 数据源2 -->
<bean id = "dataSourceRes" class = "com.mchange.v2.c3p0.ComboPooledDataSource" >
<property name="driverClass" value="${c3p0.driverClass}"></property>
<property name="jdbcUrl" value="${c3p0.urlRES}"></property>
<property name="user" value="${c3p0.userRES}"></property>
<property name="password" value="${c3p0.passwordRES}"></property>
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"></property>
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property>
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"></property>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property>
<property name="minPoolSize" value="${c3p0.minPoolSize}"></property>
<property name="acquireRetryDelay" value="1000"></property>
<property name="acquireRetryAttempts" value="60"></property>
<property name="breakAfterAcquireFailure" value="false"></property>
</bean>
<bean id="sqlMapClientRes" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSourceRes">
<ref bean="dataSourceRes" />
</property>
<property name="configLocation" value="classpath:sqlmap-config.xml"></property>
</bean>
<bean id="sqlMapClientTemplateRes" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClientRes">
<ref bean="sqlMapClientRes" />
</property>
</bean>
<!-- 事物处理 -->
<bean id="transactionManagerRes"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSourceRes">
<ref bean="dataSourceRes" />
</property>
</bean>
<bean id="transactionInterceptorRes"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManagerRes">
<ref bean="transactionManagerRes" />
</property>
<!-- <property name="transactionManagerRes">
<ref bean="transactionManagerRes"/>
</property> -->
<property name="transactionAttributes">
<props>
<!--
表示类中的所有方法都要进行连接的关闭,和事务处理。 而且Spring还提供了多种事务处理方式,其中开发只使用下面这种。
PRPAGATION_REQUIRED:如果之前没有事务,则开始一个事务,如果之前有事务,则将当前操作合并到该事务中。
PRPAGATION_REQUIRED_NEW:无论之前是否有事务,都开始一个新的事务。
PRPAGATION_REQUIRED_NEVER:不支持事务,使用自动提交。
-->
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*ServiceImpl</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
<value>transactionInterceptorRes</value>
</list>
</property>
</bean>
dao层
@Component
public class SimpleResDaoImpl extends SqlMapClientDaoSupport implements SimpleResDao {
@Autowired
public SimpleResDaoImpl(SqlMapClientTemplate sqlMapClientTemplateRes) {
super.setSqlMapClientTemplate(sqlMapClientTemplateRes);
}
}
@Component
public class SimpleDaoImpl extends SqlMapClientDaoSupport implements SimpleDao {
@Autowired
public SimpleDaoImpl(SqlMapClientTemplate sqlMapClientTemplate) {
super.setSqlMapClientTemplate(sqlMapClientTemplate);
}
}
------解决思路----------------------
路过,支持lz