Spring bean xml 配置继承
来源:互联网 发布:淘宝火影忍者手游cdk 编辑:程序博客网 时间:2024/05/21 10:38
本人最近刚到一家新公司,在之前都使用spring 注解配置的方式来写代码的(个人比较喜欢注解的方式)。
但是由于接手的项目是用xml的方式,对于xml配置的方式比较不熟悉。
现在要整合hibernate试用两个数据源(A,B) , DAO层都继续一个父类(假如父类为BasicDaoImpl),该父类又包含 one,two,three属性。
xml注入bean是使用autowire="byType",根据类型注入。
<bean id="one" class="com.xxx.One"><property name="dataSource" value="dataSource" /></bean><bean id="two" class="com.xxx.Two"><property name="dataSource" value="dataSource" /></bean><bean id="three" class="com.xxx.Three"><property name="dataSource" value="dataSource" /></bean><bean id="oneDao" class="com.xxx.dao.OneDaoImpl" autowire="byType" />
但是 one,two,three都依赖数据源,所以必须明确指定是某个数据源.
<bean id="dataSourceA" class="com.alibaba.druid.pool.DruidDataSource" /><bean id="dataSourceB" class="com.alibaba.druid.pool.DruidDataSource" /><bean id="oneA" class="com.xxx.OneA"><property name="dataSource" value="dataSourceA" /></bean><bean id="twoA" class="com.xxx.TwoA"><property name="dataSource" value="dataSourceA" /></bean><bean id="threeA" class="com.xxx.ThreeA"><property name="dataSource" value="dataSourceA" /></bean><bean id="oneB" class="com.xxx.OneB"><property name="dataSource" value="dataSourceB" /></bean><bean id="twoB" class="com.xxx.TwoB"><property name="dataSource" value="dataSourceB" /></bean><bean id="threeB" class="com.xxx.ThreeB"><property name="dataSource" value="dataSourceB" /></bean><bean id="oneDao" class="com.xxx.dao.OneDaoImpl"><property name="one" value="oneA" /><property name="two" value="twoA" /><property name="three" value="threeA" /></bean><bean id="twoDao" class="com.xxx.dao.DaoImpl"><property name="one" value="oneB" /><property name="two" value="twoB" /><property name="three" value="threeB" /></bean>
但是 one,two,three都依赖数据源,所以必须明确指定是某个数据源
<property name="one" value="oneA" /><property name="two" value="twoA" /><property name="three" value="threeA" />
后面找到资料:http://www.yiibai.com/spring/spring-bean-configuration-inheritance.html,用抽象继承的方式,免去以上重复的配置<bean id="basicDaoImplA" class="com.xxx.BasicDaoImpl"abstract="true"><property name="one" value="oneA" /><property name="two" value="twoA" /><property name="three" value="threeA" /></bean><bean id="basicDaoImplB" class="com.xxx.BasicDaoImpl" abstract="true"><property name="one" value="oneB" /><property name="two" value="twoB" /><property name="three" value="threeB" /></bean><bean id="oneDao" class="com.xxx.dao.OneDaoImpl" parent="basicDaoImplA"/><bean id="twoDao" class="com.xxx.dao.TwoDaoImpl" parent="basicDaoImplB"/>抽象类需要配置abstract="true"。
还有其他类型的模版配置,可以点击查看资料
记录一下,第一次的写博客,请指教批评。
阅读全文
1 0
- Spring bean xml 配置继承
- Spring Bean配置继承
- Spring bean配置继承
- Spring 继承Bean配置
- Spring Bean在XML配置中的父子继承
- Spring继承Bean的配置
- Spring bean.xml的配置
- Spring Bean的XML配置
- Spring 配置bean定义的继承
- Spring中bean的基本xml配置
- Spring中bean的基本xml配置
- Spring中bean的基本xml配置
- Spring中bean的基本xml配置
- Spring-config.xml数据库操作Bean配置
- Spring中bean的基本xml配置
- spring配置bean.xml头文件模板
- Spring中bean的基本xml配置
- 【Spring】装配Bean-(1)-使用XML配置
- Excel 代码编写 统一去掉单元格左上角的三角符号
- 引用与指针有何区别?何时只能使用指针不能使用引用?
- Windows Native WIFI 编程
- 自动行为操控Steering(十一)—分散(群体操控)
- linux 解决笔记本不能调节屏幕亮度问题
- Spring bean xml 配置继承
- BMP图片格式
- JavaWeb实现文件上传下载功能实例解析以及项目工程示例下载
- 细节之Integer数值(==)比较问题
- CodeForces 732B Cormen — The Best Friend Of a Man
- Xcode 符号断点(Symbolic Breakpoint)
- 移动端,pc短添加好友、群功能
- PAT1016
- 各向异性扩散 Anisotropic diffusion