标签:dispatch location http pac 方法 pre text value private
1、byName使用:
2、byType:byType:寻找和属性类型相同的bean,找不到、装不上, 找到多个抛出异常
3、constructor:autowire="constructor"
说明:查找和bean的构造参数一致的一个或多个bean,若找不到或找到多个,抛异常。按照参数的类型装配
4、autodetect
说明:autowire="autodetect"
2和3之间选一种方式,不确定性处理跟他们一致
5、defualt
这个需要在<beans defualt-autowire="指定"/>
当在beans指定了defualt-autowire后,所有的bean的默认的autowire就是指定的装配方法。
当<beans defualt-autowire="指定"/>,没有defualt-autowire="指定",则默认是defualt-autowire="no"
.properties文件(分散配置)
DBUtil文件
1 package com.hsp.dispatch; 2 3 public class DBUtil { 4 5 private String drivername; 6 private String url; 7 private String name; 8 private String pwd; 9 public String getDrivername() { 10 return drivername; 11 } 12 public void setDrivername(String drivername) { 13 this.drivername = drivername; 14 } 15 public String getUrl() { 16 return url; 17 } 18 public void setUrl(String url) { 19 this.url = url; 20 } 21 public String getName() { 22 return name; 23 } 24 public void setName(String name) { 25 this.name = name; 26 } 27 public String getPwd() { 28 return pwd; 29 } 30 public void setPwd(String pwd) { 31 this.pwd = pwd; 32 } 33 34 35 }
使用分散配置
spring中插入数据库连接,用户名,密码等
1 <!-- DBUtil --> 2 <bean id = "dbutil" class="com.hsp.dispatch.DBUtil"> 3 <property name="name" value="scott"/> 4 <property name="drivername" value="oracle:jdbc:driver:OracleDirver"/> 5 <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:hsp"/> 6 <property name="pwd" value="tiger"/> 7 </bean>
不使用分散配置
spring部分改为
1 <!-- 引入db.properties --> 2 <context:property-placeholder location="classpath:com/hsp/dispatch/db.properties"/> 3 <!-- DBUtil $为占位符 --> 4 <bean id = "dbutil" class="com.hsp.dispatch.DBUtil"> 5 <property name="name" value="${name}"/> 6 <property name="drivername" value="${drivername}"/> 7 <property name="url" value="${url}"/> 8 <property name="pwd" value="${pwd}"/> 9 </bean>
.properties为
1 name=scott 2 3 drivername=oracle:jdbc:driver:OracleDirver 4 5 url=jdbc:oracle:thin:@127.0.0.1:1521:hsp 6 7 pwd=tiger
标签:dispatch location http pac 方法 pre text value private
原文地址:http://www.cnblogs.com/20-12-55/p/6846105.html