bean配置

启用注解

<context:annotation-config/>

使用spring的特殊bean

对bean

BeanPostProcessor

spring本身提供的特殊bean

1.实现了BeanPostProcessor的后置处理器

2.PropertyPlaceholderConfigurer.

分散配置(有两种方式引入文件)

使用spring的特殊bean,完成分散配置。

beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
">
<!-- 引入我们的db. -->
<context:property-placeholder location="classpath:com/hsp/dispatch/db.properties,classpath:com/hsp/dispatch/db2.properties"/> <bean id="dbutil" class="com.hsp.dispatch.DBUtil">
<property name="name" value="${name}"/>
<property name="drivername" value="${drivername}"/>
<property name="url" value="${url}"/>
<property name="pwd" value="${pwd}"/>
</bean> <bean id="dbutil2" class="com.hsp.dispatch.DBUtil">
<property name="name" value="${name}"/>
<property name="drivername" value="${drivername}"/>
<property name="url" value="${url}"/>
<property name="pwd" value="${pwd}"/> </bean>
</beans>

说明:当通过context:property-placeholder引入属性文件的时候,有多个需要使用,号间隔。

package com.hsp.dispatch;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class App1 {
public static void main(String[] args) { ApplicationContext ac = new ClassPathXmlApplicationContext("com/hsp/dispatch/beans.xml"); DBUtil dbUtil = (DBUtil)ac.getBean("dbutil2");
System.out.println(dbUtil.getDrivername());
System.out.println(dbUtil.getName());
System.out.println(dbUtil.getUrl());
System.out.println(dbUtil.getPwd()); } }

db2.properties

name=root2
drivername=oracle:jdbc:driverDriver2
url=jdbc:oracle:thin:@127.0.0.1:1521:hsp2
pwd=tiger2

使用占位符变量代替bean装配文件中的硬编码配置。占位符采用${variable}形式。

spring学习(5)的更多相关文章

  1. spring 学习之 bean 的注入方式 property和constructor-arg的使用方式

    spring 学习之 bean 的注入方式 property和constructor-arg的使用方式. bean的注入方式: property 注入是: 通过setxx方法注入. construct ...

  2. Spring学习之AOP总结帖

    AOP(面向方面编程),也可称为面向切面编程,是一种编程范式,提供从另一个角度来考虑程序结构从而完善面向对象编程(OOP). 在进行 OOP 开发时,都是基于对组件(比如类)进行开发,然后对组件进行组 ...

  3. Spring学习之第一个AOP程序

    IOC和AOP是Spring的两大基石,AOP(面向方面编程),也可称为面向切面编程,是一种编程范式,提供从另一个角度来考虑程序结构从而完善面向对象编程(OOP). 在进行 OOP 开发时,都是基于对 ...

  4. MyEclipse Spring 学习总结三 SpringMVC

    MyEclipse Spring 学习总结三 SpringMVC 一.SpringMVC原理 1.Springmvc 框架介绍 1)Spring 框架停工了构建Web应用程序的全功能MVC模块.Spr ...

  5. Spring学习 Ioc篇(一 )

    一直以来忙于项目的开发,Spring虽然不用,一直想系统地学习一下,想看看它的源码,都没有时间,这段时间比较充裕,就索性先把Spring学习下,熟悉各个功能再去探究它内部的实现.就从Ioc篇开始学习. ...

  6. Spring学习(三)——Spring中的依赖注入的方式

    [前面的话] Spring对我太重要了,做个关于web相关的项目都要使用Spring,每次去看Spring相关的知识,总是感觉一知半解,没有很好的系统去学习一下,现在抽点时间学习一下Spring.不知 ...

  7. Spring学习(二)——Spring中的AOP的初步理解[转]

      [前面的话] Spring对我太重要了,做个关于web相关的项目都要使用Spring,每次去看Spring相关的知识,总是感觉一知半解,没有很好的系统去学习一下,现在抽点时间学习一下Spring. ...

  8. 【Spring学习笔记-MVC-3.1】SpringMVC返回Json数据-方式1-扩展

    <Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...

  9. Spring学习8-Spring事务管理

      http://blog.sina.com.cn/s/blog_7ffb8dd501014e0f.html   Spring学习8-Spring事务管理(注解式声明事务管理) 标签: spring注 ...

  10. Spring学习之Ioc控制反转(1)

    开始之前: 1. 本博文为原创,转载请注明出处 2. 作者非计算机科班出身,如有错误,请多指正 ---------------------------------------------------- ...

随机推荐

  1. man page及info page用法

    Linux系统的在线求助man page与info page 先来了解一下Linux有多少命令呢?在文本模式下,你可以直接按下两个[Tab]按键,看看总共有多少命令可以让你用? [vbird@www ...

  2. php判断页面是否是微信打开的示例(微信打开网页)

    代码如下: $user_agent = $_SERVER['HTTP_USER_AGENT'];if (strpos($user_agent, 'MicroMessenger') === false) ...

  3. 为什么 java wait/notify 必须与 synchronized 一起使用,jvm究竟做了些什么

    这个课题提出来的是原先的线程并发解决的思路.目前解决线程并发,可以是lock接口结合condition  并发问题一直以来就是线程必不可少的话题. java 是第一个内置对多线程支持的主流编程语言.在 ...

  4. COM组件多接口对象模型

    COM组件有两种接口类型,Dual and Custom,如下图所示.本文说的是Custom.所谓多接口COM对象是指此COM对象实现了多于一个的自定义接口,即Custom接口. 接口图如下: 需要注 ...

  5. ubuntu 及 postgredql 安装配置小坑摘录

    ubuntu 16.04.1 安装 Ubuntu Server 16.04.1安装配置图解教程,按教程修改局域网static IP 开启sftp必须 解决SSH服务拒绝密码,之后才能欢乐地使用file ...

  6. 让WebRTC支持H264编解码

    近期实验了下怎样让WebRTC支持H264编码.记录下,供有须要的人參考. 说明一下,我是在 Ubuntu Server 14.04 下编译的 WebRTC ,使用 native(C++) api 开 ...

  7. python 基础 9.9 查询数据

      #/usr/bin/python #-*- coding:utf-8 -*- #@Time   :2017/11/24 4:21 #@Auther :liuzhenchuan #@File   : ...

  8. bash编程基础

    bash变量 变量命名: 1.不能使用程序中的关键字(保留字) 2.只能使用数字.字母和下划线,且不能以数字开头 3.要见名知义 变量类型: 数值型:精确数值(整数),近似数值(浮点型) 字符型:ch ...

  9. 修改maven的war包生成路径

    因为要配合jenkins,所以控制了war包的生成目录: <plugins> <!--打war包到指定的目录下 --> <plugin> <groupId&g ...

  10. table表格用tbody新属性获取DOM元素

    // alert(oTab.getElementsByTagName("tbody")[0] // .getElementsByTagName('tr')[1] // .getEl ...