使用Spring(四)构造器参数匹配(类型匹配 ,索引)
来源:互联网 发布:网络美工岗位要求 编辑:程序博客网 时间:2024/05/16 08:26
1.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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean name="mc1" class="com.yw.test04.MyClass1"><!-- 构造器参数类型匹配 --><constructor-arg value="1" type="int"></constructor-arg><constructor-arg><bean class="com.yw.test04.MyClass2" /></constructor-arg><constructor-arg><bean class="com.yw.test04.MyClass3" /></constructor-arg></bean><bean id="exampleBean" class="com.yw.test04.MyClass1"><!-- 构造器参数的索引 --><constructor-arg index="0" value="2" /><constructor-arg><bean class="com.yw.test04.MyClass2" /></constructor-arg><constructor-arg><bean class="com.yw.test04.MyClass3" /></constructor-arg></bean></beans>
2.
package com.yw.test04;public class MyClass2{}
package com.yw.test04;public class MyClass3{}
package com.yw.test04;public class MyClass1{public MyClass1(int i,MyClass2 mc2,MyClass3 mc3){System.out.println("=====public MyClass1(int i,MyClass2 mc2,MyClass3 mc3)=======");System.out.println("i="+i);System.out.println("mc2="+mc2);System.out.println("mc3="+mc3);}}
package com.yw.test04;import org.springframework.beans.factory.BeanFactory;import org.springframework.beans.factory.xml.XmlBeanFactory;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.core.io.ClassPathResource;import org.springframework.core.io.FileSystemResource;import org.springframework.core.io.Resource;public class Test01{public static void main(String[] args){//实例化容器方法三ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "com/yw/test04/applicationContext.xml"});// of course, an ApplicationContext is just a BeanFactoryBeanFactory factory = (BeanFactory) context;//构造器参数的解析//Object obj=factory.getBean("mc1");Object obj=factory.getBean("exampleBean");System.out.println("obj="+obj);}}
3.运行
0 0
- 使用Spring(四)构造器参数匹配(类型匹配 ,索引)
- JMock实践---(四)参数匹配
- Spring的Controller请求方法中参数名匹配,但是参数类型不同会报404
- python(第三天):参数匹配类型
- Python函数非匹配参数类型传递
- 类型匹配
- 使用spring实现读写分离(mysql主从复制)四-优化改进切面实现,使用事务策略规则匹配
- Python匹配对象与索引使用
- 论文阅读-文本匹配(三)MatchPyramid(构造匹配矩阵)
- 使用PreparedStatementSetter 设置参数跟 表字段类型不匹配出现的错误
- grep精确匹配--w参数的使用
- Scala模式匹配下提取器构造
- List匹配索引删除
- AOP源码解析(四)寻找匹配的增强器
- 常量引用型形参躲避模板类型参数精确匹配
- scanf()函数的参数输入类型不匹配问题
- 匹配极其相关问题(四)
- [Elasticsearch] 部分匹配 (四) - 索引期间优化ngrams及索引期间的即时搜索
- Android Studio报错Could not read cache value from “...” 的解决方法
- struts2+spring+hibernate+maven搭建简单web项目
- Android 内存缓存 LruCache
- 面向接口编程与面向实现编程
- 彩妆热卖产品列表
- 使用Spring(四)构造器参数匹配(类型匹配 ,索引)
- UNDOTBS01.DBF太大的解决方法
- PHP的COOKIE原理介绍与使用
- 设计模式之建造者模式(Builder)
- Ndk 生成.so(win7)
- 解析app出现闪退,解析.crash文件
- Android Wear创建通知的几种方式
- Linux RPM方式安装MySQL5.6.31
- PHP的SESSION原理介绍与使用