spring学习(5)
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)的更多相关文章
- spring 学习之 bean 的注入方式 property和constructor-arg的使用方式
spring 学习之 bean 的注入方式 property和constructor-arg的使用方式. bean的注入方式: property 注入是: 通过setxx方法注入. construct ...
- Spring学习之AOP总结帖
AOP(面向方面编程),也可称为面向切面编程,是一种编程范式,提供从另一个角度来考虑程序结构从而完善面向对象编程(OOP). 在进行 OOP 开发时,都是基于对组件(比如类)进行开发,然后对组件进行组 ...
- Spring学习之第一个AOP程序
IOC和AOP是Spring的两大基石,AOP(面向方面编程),也可称为面向切面编程,是一种编程范式,提供从另一个角度来考虑程序结构从而完善面向对象编程(OOP). 在进行 OOP 开发时,都是基于对 ...
- MyEclipse Spring 学习总结三 SpringMVC
MyEclipse Spring 学习总结三 SpringMVC 一.SpringMVC原理 1.Springmvc 框架介绍 1)Spring 框架停工了构建Web应用程序的全功能MVC模块.Spr ...
- Spring学习 Ioc篇(一 )
一直以来忙于项目的开发,Spring虽然不用,一直想系统地学习一下,想看看它的源码,都没有时间,这段时间比较充裕,就索性先把Spring学习下,熟悉各个功能再去探究它内部的实现.就从Ioc篇开始学习. ...
- Spring学习(三)——Spring中的依赖注入的方式
[前面的话] Spring对我太重要了,做个关于web相关的项目都要使用Spring,每次去看Spring相关的知识,总是感觉一知半解,没有很好的系统去学习一下,现在抽点时间学习一下Spring.不知 ...
- Spring学习(二)——Spring中的AOP的初步理解[转]
[前面的话] Spring对我太重要了,做个关于web相关的项目都要使用Spring,每次去看Spring相关的知识,总是感觉一知半解,没有很好的系统去学习一下,现在抽点时间学习一下Spring. ...
- 【Spring学习笔记-MVC-3.1】SpringMVC返回Json数据-方式1-扩展
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
- Spring学习8-Spring事务管理
http://blog.sina.com.cn/s/blog_7ffb8dd501014e0f.html Spring学习8-Spring事务管理(注解式声明事务管理) 标签: spring注 ...
- Spring学习之Ioc控制反转(1)
开始之前: 1. 本博文为原创,转载请注明出处 2. 作者非计算机科班出身,如有错误,请多指正 ---------------------------------------------------- ...
随机推荐
- applicationContext-XXX.xml和XXX-servlet.xml的区别
1.ApplicationContext.xml 是spring 全局配置文件,用来控制spring 特性的 2.dispatcher-servlet.xml 是spring mvc里面的,控制器. ...
- Eval,Bind,<% %>,<%# %>和<%= %> 笔记
1.<% %>用来绑定后台代码 如: < % for(int i=0;i<100;i++) { Reaponse.Write(i.ToString()); } %> 2. ...
- C语言中的一个*和[]优先级问题
最近写着玩了这么一段代码 int Init(int **T, int v1, int v2, int v3) { *sizeof(int)))) exit(-); *T[]=v1, *T[]=v2, ...
- [root@localhost ~]#各项解释
[root@localhost ~]# 解释: [登录用户@主机名 索引目录(~家目录,当前所在的目录)]#号代表超级用户,$普通用户
- LCD驱动程序(二)
上节我们主要是对fb_info结构体的配置,对fb_info结构体的配置主要分为一下步骤: static int lcd_init(void){ /* 1. 分配一个fb_info */ s3c_lc ...
- 服务器端获取表单数据的编码解码问题(servlet)
首先需要明确指出的是,这里的服务器是指tomcat. 在页面没有明确指定编码的情况下,客户端通过input标签和字符串向服务器传递两个值param1和param2.如果直接使用request.getP ...
- zoj 3716 Ribbon Gymnastics【神奇的计算几何】
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3716 来源:http://acm.hust.edu.cn/vjudg ...
- 页游手游服务器(一)c实现拓展lua网络
把工作几年服务器相关的部分内容,通过服务器解决方案,做一次总结.整个实现的主体是lua脚本,lua实现主要缺少的两大块:1网络部分2数据库部分这两部分必须通过c/c++做扩展先来做net,主要是服务器 ...
- thymeleaf基本应用
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...
- [luogu3413]萌数
[luogu3413]萌数 luogu 考虑数位dp 怎么判断一个数是不是萌数? 只要知道其中某一位和它的前一位相等或者和前一位的前一位相等,那么它就是一个萌数 什么样的数不是萌数? 对于它的每一位都 ...