Spring测试

好几天都在做spring源码分析,初步分析

package cn.com.nuoter.playbar.groupon;

import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ClassPathResource;

import cn.com.nuoter.playbar.groupon.service.GrouponAllService;

public class TestSpring {
public static void main(String[] args) throws Exception {
StringBuffer buffer=new StringBuffer();
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"/conf/spring/applicationContext*.xml");
GrouponAllService service = (GrouponAllService) ctx.getBean("groupService"); //spring beanId 必须用接口类进行强转和接收
buffer.append("是否存在此bean:").append(ctx.containsBean("groupService")).append("\n");
buffer.append("此bean是否单例:").append(ctx.isSingleton("groupService")).append("\n");
buffer.append("根据bean的别名判断是否是目标类类型:").append(ctx.isTypeMatch("groupService", GrouponAllService.class));
GrouponAllService impl= (GrouponAllService)ctx.getBean("groupService",GrouponAllService.class);
aa();
System.out.println(buffer.toString());
}

public static void aa(){
ClassPathResource res = new ClassPathResource("/conf/spring/applicationContext-groupon.xml");
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
System.out.println("此配置文件个共配置了"+reader.loadBeanDefinitions(res)+"类文件");
//GrouponAllService service = (GrouponAllService)factory.getBean("groupService"); //spring beanId 必须用接口类进行强转和接收
System.out.println("是否存在此bean:"+factory.containsBean("groupService"));


System.out.println("-----------------------------------------------------------");
}

}

[color=blue]输出如下:[/color]
[img]http://dl.iteye.com/upload/picture/pic/69576/2624218d-752a-3972-b4e4-451cec9834a8.jpg[/img]

各位有什么建议,请指教。。。刚开始研究
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值