Spring的DI注入详解及Spring配置信息

Dependence Injection 依赖注入,是在Spring IOC(控制反转)中为所创建对象属性赋值的方式,以下介绍常用的注入方式。

首先将Spring引入配置信息展示以下:

Spring配置信息,一般取名为 applicationContext.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"	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>

可以下载Spring IDE 插件,用起来更得心应手,文末附上下载链接。
首先我们先创建一个学生类,并写相应属性:

public class Student {
	private List<Address> address;
	private int age;
	private String gender;
	private List<String> hobbys;
	private int id;
	private String name;
	private Address[] address1;
	private Map<String, Integer> teach;

直接看代码,更加容易理解,注意对应着属性类型去看。

<bean id="address1" class="com.itqf.student.Address">
		<property name="province" value="上海"></property>
		<property name="city" value="上海"></property>
		<property name="area" value="宝山区"></property>
	</bean>
	<bean id="address2" class="com.itqf.student.Address">
		<property name="province" value="北京"></property>
		<property name="city" value="平坛"></property>
		<property name="area" value="高新区"></property>
	</bean>
	<bean id="address3" class="com.itqf.student.Address">
		<property name="province" value="江苏"></property>
		<property name="city" value="徐州"></property>
		<property name="area" value="云龙区"></property>
	</bean>

	<!--Student student = new Student() -->
	<bean id="student" class="com.itqf.student.Student">
		<property name="id" value="1001" />
		<property name="name" value="詹三" />
		<property name="age" value="18" />
		<property name="gender" value="公" />

		<!-- 基本数据类型 -->
		<property name="salary">
			<array>
				<value>1000</value>
				<value>2000</value>
				<value>3000</value>
			</array>
		</property>

		<!-- 基本数据类型 -->
		<property name="hobbys">
			<list>
				<value>唱歌</value>
				<value>跳舞</value>
				<value>书法</value>
			</list>
		</property>

		<!-- 引用数据类型 -->
		<property name="Address">
			<list>
				<ref bean="address1" />
				<ref bean="address2" />
				<ref bean="address3" />
			</list>
		</property>

		<!-- 引用数据类型 -->
		<property name="address1">
			<array>
				<ref bean="address1" />
				<ref bean="address2" />
				<ref bean="address3" />
			</array>
		</property>
		<property name="teach">
			<map>
				<entry key="英语" value="11"></entry>
				<entry key="语文" value="2222"></entry>
				<entry key="数学" value="333"></entry>
			</map>
		</property>
	</bean>

其实,常用的也就这几种,多加使用即可,俗话说的好,孰能生巧。
这里给下Spring IDE下载链接哈,使用后,6的飞起!!!!!
下载前,注意查看自己ecplice版本。
在这里插入图片描述
eclipse4.7.3a版本:

http://download.springsource.com/release/TOOLS/update/3.9.4.RELEASE/e4.7/springsource-tool-suite-3.9.4.RELEASE-e4.7.3a-updatesite.zip

eclipse4.7.3版本:

http://download.springsource.com/release/TOOLS/update/3.9.3.RELEASE/e4.7/springsource-tool-suite-3.9.3.RELEASE-e4.7.3-updatesite.zip

eclipse4.7.2版本:

http://download.springsource.com/release/TOOLS/update/3.9.2.RELEASE/e4.7/springsource-tool-suite-3.9.2.RELEASE-e4.7.2-updatesite.zip

eclipse4.7.1a版本:

http://download.springsource.com/release/TOOLS/update/3.9.1.RELEASE/e4.7/springsource-tool-suite-3.9.1.RELEASE-e4.7.1a-updatesite.zip

eclipse4.7.0版本:

http://download.springsource.com/release/TOOLS/update/3.9.0.RELEASE/e4.7/springsource-tool-suite-3.9.0.RELEASE-e4.7.0-updatesite.zip

eclipse4.6.3版本:

http://download.springsource.com/release/TOOLS/update/3.8.4.RELEASE/e4.6/springsource-tool-suite-3.8.4.RELEASE-e4.6.3-updatesite.zip

eclipse4.6.2版本:

http://download.springsource.com/release/TOOLS/update/3.8.3.RELEASE/e4.6/springsource-tool-suite-3.8.3.RELEASE-e4.6.2-updatesite.zip

eclipse4.6.1版本:

http://download.springsource.com/release/TOOLS/update/3.8.2.RELEASE/e4.6/springsource-tool-suite-3.8.2.RELEASE-e4.6.1-updatesite.zip

eclipse4.6版本:

http://download.springsource.com/release/TOOLS/update/3.8.1.RELEASE/e4.6/springsource-tool-suite-3.8.1.RELEASE-e4.6-updatesite.zip

http://download.springsource.com/release/TOOLS/update/3.8.0.RELEASE/e4.6/springsource-tool-suite-3.8.0.RELEASE-e4.6-updatesite.zip

eclipse4.5.2版本:

http://download.springsource.com/release/TOOLS/update/3.7.3.RELEASE/e4.5/springsource-tool-suite-3.7.3.RELEASE-e4.5.2-updatesite.zip

eclipse4.5.1版本:

http://download.springsource.com/release/TOOLS/update/3.7.2.RELEASE/e4.5/springsource-tool-suite-3.7.2.RELEASE-e4.5.1-updatesite.zip

http://download.springsource.com/release/TOOLS/update/3.7.1.RELEASE/e4.5/springsource-tool-suite-3.7.1.RELEASE-e4.5.1-updatesite.zip

eclipse4.5版本:

http://download.springsource.com/release/TOOLS/update/3.7.0.RELEASE/e4.5/springsource-tool-suite-3.7.0.RELEASE-e4.5-updatesite.zip

eclipse4.4.2版本:

http://download.springsource.com/release/TOOLS/update/3.6.4.RELEASE/e4.4/springsource-tool-suite-3.6.4.RELEASE-e4.4.2-updatesite.zip

eclipse4.4.1版本(SR1):

http://download.springsource.com/release/TOOLS/update/3.6.3.SR1/e4.4/springsource-tool-suite-3.6.3.SR1-e4.4.1-updatesite.zip

eclipse4.4.1版本:

http://download.springsource.com/release/TOOLS/update/3.6.3.RELEASE/e4.4/springsource-tool-suite-3.6.3.RELEASE-e4.4.1-updatesite.zip

http://download.springsource.com/release/TOOLS/update/3.6.2.RELEASE/e4.4/springsource-tool-suite-3.6.2.RELEASE-e4.4.1-updatesite.zip

eclipse4.4版本:

http://download.springsource.com/release/TOOLS/update/3.6.1.RELEASE/e4.4/springsource-tool-suite-3.6.1.RELEASE-e4.4-updatesite.zip

http://download.springsource.com/release/TOOLS/update/3.6.0.RELEASE/e4.4/springsource-tool-suite-3.6.0.RELEASE-e4.4-updatesite.zip

eclipse4.3.2版本:

http://download.springsource.com/release/TOOLS/update/3.5.1.RELEASE/e4.3/springsource-tool-suite-3.5.1.RELEASE-e4.3.2-updatesite.zip

http://download.springsource.com/release/TOOLS/update/3.5.0.RELEASE/e4.3/springsource-tool-suite-3.5.0.RELEASE-e4.3.2-updatesite.zip

eclipse4.3.1版本:

http://download.springsource.com/release/TOOLS/update/3.4.0.RELEASE/e4.3/springsource-tool-suite-3.4.0.RELEASE-e4.3.1-updatesite.zip

eclipse4.3版本:

http://download.springsource.com/release/TOOLS/update/3.3.0.RELEASE/e4.3/springsource-tool-suite-3.3.0.RELEASE-e4.3-updatesite.zip

eclipse4.2.2版本:

http://download.springsource.com/release/TOOLS/update/3.2.0.RELEASE/e4.2/springsource-tool-suite-3.2.0.RELEASE-e4.2.2-updatesite.zip

eclipse4.2版本:

http://download.springsource.com/release/TOOLS/update/3.1.0.RELEASE/e4.2/springsource-tool-suite-3.1.0.RELEASE-e4.2-updatesite.zip


注:个人学习见解,不足之处还望少侠谅解,如有需要改正之处,请指教,谢谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值