Bean装配--xml
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的更多相关文章
- 使用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...”. 原 ...
- Spring基础使用(一)--------IOC、Bean的XML方式装配
基础 1.xml文件基础格式: <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns=&q ...
- 【Spring】Spring的bean装配
前言 bean是Spring最基础最核心的部分,Spring简化代码主要是依赖于bean,下面学习Spring中如何装配bean. 装配bean Spring在装配bean时非常灵活,其提供了三种方式 ...
- Spring Bean装配方式
Spring装配机制 在xml中进行显示配置 在Java中进行显示配置 隐式bean发现机制和自动装配 自动化装配bean 组件扫描(component scanning),Spring会自动发现应用 ...
- Spring使用笔记(二)Bean装配
Bean装配 Spring提供了3种装配机制: 1)隐式的Bean发现机制和自动装配 2)在Java中进行显示装配 3)在XML中进行显示装配 一)自动化装配 1.指定某类为组件类: @Compone ...
- Spring对Bean装配详解
1.Spring提供了三种装配bean的方式: 2.自动装配bean: 3.通过Java代码装配bean 4.通过XML装配bean 前言:创建对象的协作关系称为装配,也就是DI(依赖注入)的本质.而 ...
- Spring Bean装配学习
解释:所谓装配就是把一个类需要的组件给它设置进去,英文就是wire,wiring:注解Autowire也叫自动装配. 目前Spring提供了三种配置方案: 在XML中进行显式的配置 在Java中进行显 ...
- spring Bean装配的几种方式简单介绍
Spring容器负责创建应用程序中的bean同时通过ID来协调这些对象之间的关系.作为开发人员,我们需要告诉Spring要创建哪些bean并且如何将其装配到一起. spring中bean装配有两种方式 ...
- 使用Spring IoC进行Bean装配
Spring概述 Spring的设计严格遵从的OCP(开闭原则),保证对修改的关闭,也就是外部无法改变spring内部的运行流程:提供灵活的扩展接口,也就是可以通过extends,implements ...
随机推荐
- [部署开发环境]部署django的生成环境nginx+uwsgi+django
#教程 # ubuntu部署django项目 # 部署准备 - ubuntu操作系统 -- vagrant虚拟 - Nginx服务器 -- 安装在ubuntu的web服务器 - uWSGI应用协议服务 ...
- gulp-API介绍
使用gulp,一般只需要用4个API:gulp.src(),gulp.dest(),gulp.task(),gulp.watch(). 1. gulp.src() 用来获取流的,但是要注意的是这个流里 ...
- ZooKeeper客户端 zkCli.sh 节点的配额设置
首先使用 zkCli.sh 连接上ZooKeeper服务器 配额设置命令格式如下: setquota -n|-b val path -n:val设置子节点个数 -b:val设置节点的数据长度 如果我们 ...
- CSS使用示例
CSS的存在就是将网页的内容与内容展示的方式进行了分离. 使用CSS的方式有好几种,最常用的是通过引入外部CSS文件进行使用 HTML <!DOCTYPE html> <html&g ...
- VMware ESXI 5.5 注册码
VMware ESXI 5.5 注册码 ESXI 注册码0A42V-8M182-3ZZ88-R21N6-32K5H ESXi Server许可证类型产品: Mware vSphere 5 Enterp ...
- [hdu6428]Problem C. Calculate
题目大意:有$T(1\leqslant T\leqslant 10)$组数据,每组数据给你$A,B,C(0<A,B,C\leqslant 10^7)$,求$\sum\limits_{i=1}^A ...
- [hdu6437]Problem L. Videos
题目大意:有$n$个小时,有$m$个节目(每种节目都有类型$0/1$),有$k$个人,一个人连续看相同类型的节目会扣$w$快乐值. 每一种节目有都一个播放区间$[l,r]$.每个人同一时间只能看一个节 ...
- Eclipse 日文乱码怎么解决Shift_JIS
https://jingyan.baidu.com/article/870c6fc325a691b03fe4beac.html Eclipse设置编码的地方主要有三处,这三处的设置都会影响中文的显示. ...
- HTTP Basic 机制
package com.enation.app.shop.component.payment.plugin.cod; import java.io.IOException; import java.u ...
- Java中Collections的binarySearch方法
方法一 public static <T> int binarySearch(List<? extends Comparable<? super T>> list, ...