spring+ibatis配置多个数据源出错:
<!--在Spring配置中注入的datasource数据源--><beanid="transactionManager"class="org.springframewo...
<!--在Spring配置中注入的datasource数据源 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource" />
</property>
<!-- 第二个数据源
<property name="dataSource2">
<ref local="dataSource2" />
</property>-->
</bean>
<!--引入具体的sql语句配置文件(注意:sqlMapConfig.xml文件的路径) -->
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>/WEB-INF/conf/iBatis/sqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<!--引入具体的sql语句配置文件(注意:sqlMapConfig.xml文件的路径) -->
<bean id="sqlMapClient2"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>/WEB-INF/conf/iBatis/sqlMapConfig2.xml</value>
</property>
<property name="dataSource2">
<ref local="dataSource2" />
</property>
</bean>
错误如下:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient2' defined in ServletContext resource [/WEB-INF/conf/spring/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource2' of bean class [org.springframework.orm.ibatis.SqlMapClientFactoryBean]: Bean property 'dataSource2' is not writable or has an invalid setter method. Did you mean 'dataSource'?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource2' of bean class [org.springframework.orm.ibatis.SqlMapClientFactoryBean]: Bean property 'dataSource2' is not writable or has an invalid setter method. Did you mean 'dataSource'? 展开
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource" />
</property>
<!-- 第二个数据源
<property name="dataSource2">
<ref local="dataSource2" />
</property>-->
</bean>
<!--引入具体的sql语句配置文件(注意:sqlMapConfig.xml文件的路径) -->
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>/WEB-INF/conf/iBatis/sqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<!--引入具体的sql语句配置文件(注意:sqlMapConfig.xml文件的路径) -->
<bean id="sqlMapClient2"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>/WEB-INF/conf/iBatis/sqlMapConfig2.xml</value>
</property>
<property name="dataSource2">
<ref local="dataSource2" />
</property>
</bean>
错误如下:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient2' defined in ServletContext resource [/WEB-INF/conf/spring/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource2' of bean class [org.springframework.orm.ibatis.SqlMapClientFactoryBean]: Bean property 'dataSource2' is not writable or has an invalid setter method. Did you mean 'dataSource'?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource2' of bean class [org.springframework.orm.ibatis.SqlMapClientFactoryBean]: Bean property 'dataSource2' is not writable or has an invalid setter method. Did you mean 'dataSource'? 展开
展开全部
本场 Chat 将使用 Spring Boot、Mybatis 搭建一个简易的 Java 服务,是一个不需要修改配置文件、不重启服务、动态切换数据源的项目,适合需要需要多数据源(经常变化的数据源,数据源 3 个以上等)的 Java 开发人员查阅。
该 Chat 偏向于实现动态加载数据源方式,能搭建一个能正常运行的动态多数据源的 Java 项目,同时会提供文章内所有的源码,以供读者快速搭建环境。故大部分篇幅用于描述环境搭建及应用,不会对各个技术内部进行深入。
以下是本 Chat 的核心内容:
默认数据源搭建;
创建 Map 保存数据源;
新数据源导入;
数据源持久化优化 。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询