Spring review--常用属性String、int、list、set、Map的注入
来源:互联网 发布:mac版本的greenvpn 编辑:程序博客网 时间:2024/05/29 18:48
依赖注入
组件不做定位查询,组件依赖关系、装配全部交给容器全权负责。容器会把符合依赖关系的对象通过Java属性或者构造函数传递给所需要的对象。
常用属性String、int、list、set、Map的注入方法如下:
applicationContext.xml
<span style="font-size:14px;"><?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:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"><bean id="bean1" class="com.bjpowernode.spring.Bean1"><property name="strValue" value="hello"/> <property name="intValue" value="123"/><property name="listH" ><list><value>list1</value><value>list2</value></list></property> <property name="setValue"><set><value>set1</value><value>set2</value></set></property><property name="mapValueMap" ><map><entry key="k1" value="v1"/><entry key="k2" value="v2"/></map></property></bean></beans></span>
Bean1.java
<span style="font-size:14px;">package com.bjpowernode.spring;import java.util.List;import java.util.Map;import java.util.Set;public class Bean1 {private String strValue;private int intValue;private List listH;private Set setValue;private String[] arrayValue;private Map mapValueMap;public String getStrValue() {return strValue;}public void setStrValue(String strValue) {this.strValue = strValue;}public int getIntValue() {return intValue;}public void setIntValue(int intValue) {this.intValue = intValue;}public List getListH() {return listH;}public void setListH(List listH) {this.listH = listH;}public Set getSetValue() {return setValue;}public void setSetValue(Set setValue) {this.setValue = setValue;}public String[] getArrayValue() {return arrayValue;}public void setArrayValue(String[] arrayValue) {this.arrayValue = arrayValue;}public Map getMapValueMap() {return mapValueMap;}public void setMapValueMap(Map mapValueMap) {this.mapValueMap = mapValueMap;}}</span>
InjectitonTest.java
<span style="font-size:14px;">package Test;import org.springframework.beans.factory.BeanFactory;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.bjpowernode.spring.Bean1;import junit.framework.TestCase;public class InjectionTest extends TestCase {private BeanFactory factory;@Overrideprotected void setUp() throws Exception { factory =new ClassPathXmlApplicationContext("applicationContext.xml");//获取xml文件里面的bean信息}@Overrideprotected void tearDown() throws Exception {// TODO Auto-generated method stubsuper.tearDown();}public void testInjecton1(){Bean1 baBean1=(Bean1)factory.getBean("bean1");System.out.println("bean1.strValue="+baBean1.getStrValue());System.out.println("bean1.getIntValue="+baBean1.getIntValue());System.out.println("bean1.getListValue="+baBean1.getListH());System.out.println("bean1.getSetValue="+baBean1.getSetValue());System.out.println("bean1.getArrayValue="+baBean1.getArrayValue());System.out.println("bean1.getMapValueMap="+baBean1.getMapValueMap());}}</span>
0 0
- Spring review--常用属性String、int、list、set、Map的注入
- Spring 普通属性注入(int ,String, List, Map, Set, String[])
- Spring整理 --String int List Set Map Array 普通属性注入 属性编辑器
- spring注入list set map
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- spring的list,set,map的依赖注入
- List,Set,Map,Properties的Spring注入实例
- List,Set,Map,Properties的Spring注入实例
- List,Set,Map,Properties的Spring注入实例
- Spring注入集合的值List,Set,Map,Properties
- Spring中注入List Set Map Properties的配置文件
- spring注入Set,List,Properties和Map
- C#控制台基础 获取文件大小的函数Length(优化版)
- WebSocket+node.js创建即时通信的Web聊天服务器
- android 顶部标题栏ActionBar详解
- Exynos4412 Uboot 移植(二)—— Uboot 启动流程分析
- 细说KVO & KVC & NSNotificationCenter那些事
- Spring review--常用属性String、int、list、set、Map的注入
- Android 实现仿美团下拉功能
- finalize
- 网易 地牢逃脱
- 2025 查找最大元素
- Android开发之DDMS
- Android OpenCV 实例笔记3 -- 摄像头竖屏全屏的设置
- Mysql初始化root密码和允许远程访问
- poj 3087 Shuffle'm Up