建立一个实体

package com.java.test4;

import java.util.*;

/**
* @author nidegui
* @create 2019-06-22 14:45
*/
public class People {
private Integer id;
private String name;
private String age;
private Dog dog;
private List<String> a=new ArrayList<>();
private Set<String> b=new HashSet<>();
private Map<String,Object> c=new HashMap<>(); public Integer getId() {
return id;
} public People() {
} public Dog getDog() {
return dog;
} public void setDog(Dog dog) {
this.dog = dog;
} public List<String> getA() {
return a;
} public void setA(List<String> a) {
this.a = a;
} public Set<String> getB() {
return b;
} public void setB(Set<String> b) {
this.b = b;
} public Map<String, Object> getC() {
return c;
} public void setC(Map<String, Object> c) {
this.c = c;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getAge() {
return age;
} public void setAge(String age) {
this.age = age;
} public People(Integer id, String name, String age) {
this.id = id;
this.name = name;
this.age = age;
} @Override
public String toString() {
return "People{" +
"id=" + id +
", name='" + name + '\'' +
", age='" + age + '\'' +
", dog=" + dog +
", a=" + a +
", b=" + b +
", c=" + c +
'}';
}
}

  

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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="dog1" class="com.java.test4.Dog">
<property name="name" value="javk"></property>
</bean>
<bean id="people" class="com.java.test4.People">
<property name="name" value="nidegui"></property>
<property name="id" value="1"></property>
<property name="age" value="12"></property>
<property name="dog" ref="dog1"></property>
<property name="a">
<list>
<value>a1</value>
<value>a2</value>
</list>
</property>
<property name="b">
<set>
<value>b1</value>
<value>b2</value>
</set>
</property>
<property name="c">
<map>
<entry>
<key><value>1</value></key>
<value>c1</value>
</entry>
</map>
</property>
</bean> </beans>

 

 

spring IOC bean中注入集合的更多相关文章

  1. Spring在Bean中注入集合

    以下内容引用自http://wiki.jikexueyuan.com/project/spring/injecting-collection.html: 如果你想传递多个值,如Java Collect ...

  2. spring IOC bean中注入bean

    俩个实体 package com.java.test4; /** * @author nidegui * @create 2019-06-22 14:45 */ public class People ...

  3. Spring IOC容器中注入bean

    一.基于schema格式的注入 1.基本的注入方式 (属性注入方式) 根据setXxx()方法进行依赖注入,Spring只会检查是否有setter方法,是否有对应的属性不做要求 <bean id ...

  4. 在Spring的bean中注入HttpServletRequest解密

    我们可以在Spring的bean中轻松的注入HttpServletRequest,使用@Autowired HttpServletRequest request;就可以了. 但是,为什么我们可以直接这 ...

  5. (转载)在spring的bean中注入内部类

    原文链接:http://outofmemory.cn/java/spring/spring-DI-inner-class 在spring中注入内部类,有可能会遇到如下异常信息: 2014-5-14 2 ...

  6. Spring Bean几种注入方式——setter(常用),构造器,注入内部Bean,注入集合,接口...

    依赖注入分为三种方式: 1.1构造器注入 构造器通过构造方法实现,构造方法有无参数都可以.在大部分情况下我们都是通过类的构造器来创建对象,Spring也可以采用反射机制通过构造器完成注入,这就是构造器 ...

  7. 【转】spring 装配Bean中构造参数的注入

    转载自:http://www.bianceng.cn/Programming/Java/201307/37027.htm spring 装配Bean中构造参数的注入 spring装配bean中还有一种 ...

  8. Spring在Thread中注入Bean无效的解决方式

    在Spring项目中,有时需要新开线程完成一些复杂任务,而线程中可能需要注入一些服务.而通过Spring注入来管理和使用服务是较为合理的方式.但是若直接在Thread子类中通过注解方式注入Bean是无 ...

  9. spring中如何向一个单例bean中注入非单例bean

    看到这个题目相信很多小伙伴都是懵懵的,平时我们的做法大都是下面的操作 @Component public class People{ @Autowired private Man man; } 这里如 ...

随机推荐

  1. Oracle OCP之硬解析在共享池中获取内存锁的过程

    转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/38684819 1.获得library cache Latch (1)在父游标的名柄没有找到 ...

  2. Scope Is the Enemy of Success

     Scope Is the Enemy of Success Dave Quick SCopE REFERS To A pRojECT'S SizE. How much time, effort, ...

  3. Gradle学习之创建Task的方法

    请通过下面方式下载本系列文章的Github演示样例代码: git clone https://github.com/davenkin/gradle-learning.git     Gradle的Pr ...

  4. Python3基础(一) Hello World

    对于新手一般会遇到一个问题:学习Python 2还是Python 3呢? 对于我个人而言,我是个完全的新手,没有历史包袱,所以我直接学习Python 3.我相信在未来几年,Python 3会逐步取代P ...

  5. PHP移动互联网开发笔记(3)——运算符

    原文地址:http://www.php100.com/html/php/rumen/2014/0326/6704.html 一.PHP的运算符 PHP中有丰富的运算符集,它们中大部分直接来自于C语言. ...

  6. LeetCode 977. Squares of a Sorted Array (有序数组的平方)

    题目标签:Array 题目给了我们一组 从小到大的 integers,让我们平方数字 并且 也排序成 从小到达. 因为有负数在里面,平方后,负数在array的位置会变动. 可以设left 和 righ ...

  7. TLabel和TEdit的初次显示过程

    procedure TForm1.Button2Click(Sender: TObject); var l: TLabel;begin l:=TLabel.Create(self); l.Name:= ...

  8. ios--plist

    // // main.m // 03-plist文件的回顾 // // Created by xiaomage on 15/12/29. // Copyright © 2015年 小码哥. All r ...

  9. loj 102 最小费用流

    补一发费用流的代码 %%%棒神 #include<iostream> #include<cstdio> #include<cstring> #include< ...

  10. Django - CBV装饰器实现用户登录验证

    一.使用Django自带的decorator 通常情况,使用 函数定义的view,可以直接使用 login_required 直接装饰 @login_required def index(reques ...