创建对象并赋值
@Test
public void fromSrc() {
String path = "applicationContext.xml";
ApplicationContext ac = new ClassPathXmlApplicationContext(path);
TestService ts = (TestService) ac.getBean("testService");
ts.interfaceOne();
}
@Test
public void fromRoute() {
String path = "e:" + File.separator + "path" + File.separator + "eclipsepathOfdljdfuxi" + File.separator
+ "applicationContext.xml";
ApplicationContext ac = new FileSystemXmlApplicationContext(path);
TestService ts = (TestService) ac.getBean("testService");
ts.interfaceOne();
}
/**
* 配置文件放置根目录下
*/
@Test
public void fromRootDirectory() {
String path = "applicationContext.xml";
ApplicationContext ac = new FileSystemXmlApplicationContext(path);
TestService ts = (TestService) ac.getBean("testService");
ts.interfaceOne();
}
/**
* 对象是在什么时候创建的
*/
@Test
public void fromMakeObject() {
String path = "applicationContext.xml";
ApplicationContext ac = new FileSystemXmlApplicationContext(path);
TestService ts = (TestService) ac.getBean("testService");
ts.interfaceOne();
}
/**
* 获取容器创建的个数
*/
@Test
public void fromObjectNum() {
String path = "applicationContext.xml";
ApplicationContext ac = new FileSystemXmlApplicationContext(path);
int count = ac.getBeanDefinitionCount();
System.out.println("容器创建的个数:" + count);
String[] names = ac.getBeanDefinitionNames();
for (String string : names) {
System.out.println("容器对象是:" + string);
}
}