1,bean

package com.songyan.zhangpei;

import java.util.ArrayList;

import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;

public class User {
private String userName;
private String password;
private ArrayList<String> list;
@Override
public String toString() {
String string="[usernname: "+userName+" password: "+password+" list: "+list+"]";
return string;
}
public User(){}
public User(String username,String password,ArrayList<String> list)
{
this.userName=username;
this.password=password;
this.list=list;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public ArrayList<String> getList() {
return list;
}
public void setList(ArrayList<String> list) {
this.list = list;
} }

2, 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="user1" class="com.songyan.zhangpei.User">
<property name="userName" value="zhangsan"></property>
<property name="password" value="123"></property>
<property name="list">
<list>
<value>list1</value>
<value>list2</value>
<value>list3</value>
</list>
</property>
</bean> <bean id="user2" class="com.songyan.zhangpei.User">
<constructor-arg index="0" value="lisi"></constructor-arg>
<constructor-arg index="1" value="12345"></constructor-arg>
<constructor-arg index="2" >
<list>
<value>list1</value>
<value>list2</value>
<value>list3</value>
</list></constructor-arg>
</bean>
</beans>

3, 测试

package com.songyan.zhangpei;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test {
public static void main(String[] args) {
ApplicationContext applicationContext= new ClassPathXmlApplicationContext("com/songyan/zhangpei/beanszp.xml");
User user1=(User)applicationContext.getBean("user1");
User user2=(User)applicationContext.getBean("user2");
System.out.println(user1.toString());
System.out.println(user2.toString());
}
}

4, 运行结果

user1使用的是bean装配的设值注入

user2 使用的是bean的构造器注入

Bean装配--xml的更多相关文章

  1. 使用spring框架,用xml方式进行bean装配出现“The fully qualified name of the bean's class, except if it serves...”

    使用spring框架,用xml方式进行bean装配出现“The fully qualified name of the bean's class, except if it serves...”. 原 ...

  2. Spring基础使用(一)--------IOC、Bean的XML方式装配

    基础 1.xml文件基础格式: <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns=&q ...

  3. 【Spring】Spring的bean装配

    前言 bean是Spring最基础最核心的部分,Spring简化代码主要是依赖于bean,下面学习Spring中如何装配bean. 装配bean Spring在装配bean时非常灵活,其提供了三种方式 ...

  4. Spring Bean装配方式

    Spring装配机制 在xml中进行显示配置 在Java中进行显示配置 隐式bean发现机制和自动装配 自动化装配bean 组件扫描(component scanning),Spring会自动发现应用 ...

  5. Spring使用笔记(二)Bean装配

    Bean装配 Spring提供了3种装配机制: 1)隐式的Bean发现机制和自动装配 2)在Java中进行显示装配 3)在XML中进行显示装配 一)自动化装配 1.指定某类为组件类: @Compone ...

  6. Spring对Bean装配详解

    1.Spring提供了三种装配bean的方式: 2.自动装配bean: 3.通过Java代码装配bean 4.通过XML装配bean 前言:创建对象的协作关系称为装配,也就是DI(依赖注入)的本质.而 ...

  7. Spring Bean装配学习

    解释:所谓装配就是把一个类需要的组件给它设置进去,英文就是wire,wiring:注解Autowire也叫自动装配. 目前Spring提供了三种配置方案: 在XML中进行显式的配置 在Java中进行显 ...

  8. spring Bean装配的几种方式简单介绍

    Spring容器负责创建应用程序中的bean同时通过ID来协调这些对象之间的关系.作为开发人员,我们需要告诉Spring要创建哪些bean并且如何将其装配到一起. spring中bean装配有两种方式 ...

  9. 使用Spring IoC进行Bean装配

    Spring概述 Spring的设计严格遵从的OCP(开闭原则),保证对修改的关闭,也就是外部无法改变spring内部的运行流程:提供灵活的扩展接口,也就是可以通过extends,implements ...

随机推荐

  1. ASP.NET Core [1]:Hosting(笔记)

    参考:http://www.cnblogs.com/RainingNight/p/hosting-in-asp-net-core.html

  2. 孤荷凌寒自学python第五十五天初识MongoDb数据库

    孤荷凌寒自学python第五十五天第一天初识MongoDb数据库 (完整学习过程屏幕记录视频地址在文末) 大家好,2019年新年快乐! 本来我想的是借新年第一天开始,正式尝试学习爬虫,结果今天偶然发现 ...

  3. jquery validate 使用示范

    最近应公司要求做了一个jquery的示例文件,包括:模态窗口怎么实现:jquery validate下的校验:怎么做图片特效:怎么实现异步操作:实现图片上传剪切效果等很多特效: 这里把jquery校验 ...

  4. nginx 匹配路由分发php和golang

    大概这么个形式,可以走通 server { listen ; server_name localhost; root "E:/wwwroot180/public"; # 匹配指定路 ...

  5. redis常用监控命令

    redis常用监控命令 1.实时监控redis服务收到来自应用的所有命令 1 2 3 4 5 6 7 redis-cli   127.0.0.1:6379>monitor   150996415 ...

  6. [NOWCODER] myh的超级多项式

    题面 已知$f_i=(\sum_{j=1}^ka_j{v_j}^i )\bmod 1004535809$ 给定$v_1,v_2,\ldots,v_k,f_1,f_2,\ldots f_k$ 求$f_n ...

  7. [bzoj] 2716 天使玩偶 || CDQ分治

    原题 已知n个点有天使玩偶,有m次操作: 操作1:想起来某个位置有一个天使玩偶 操作2:询问离当前点最近的天使玩偶的曼哈顿距离 显然的CDQ问题,三维分别为时间,x轴,y轴. 但是这道题的问题在于最近 ...

  8. 解决某些PC站在手机端宽度显示不正常的问题

    可以打开控制台查看html标签的宽度,发现不是当前屏幕的宽度,更改下宽度即可:用js控制下,上代码 document.getElementsByTagName('html')[0].style.wid ...

  9. Tomcat学习笔记(九)

    Tomcat Session管理 Catalina通过一个称为Session管理器的组件来管理建立Session对象,该组件由org.apache.catalina.Manager接口表示.Sessi ...

  10. ci的数据库地址

    CI在linux服务器上运行的时候,数据库配置主机名的时候必须是127.0.0.1,而不是localhost.并且phpmyadmin也有这样的要求