<?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-2.5.xsd">
<!-- 把HelloWorld这个类纳入Spring容器
1.id为bean的唯一标识
(正规的写法:
类的第一个字母变成小写,其余不变)
2.class为类的全名
-->
<bean id="helloWorld" class="cn.itcast.spring01.alias.HelloWorld"></bean>
<!-- 别名:
那么与bean中的id对应
alias 别名
-->
<alias alias="狗蛋" name="helloWorld"/>
<alias alias="王三麻子" name="helloWorld"/>
</beans>
spring启动容器
1、 在类路径下寻找配置文件来实例化容器
ApplicationContext context = new ClassPathXmlApplicationContext("cn/itcast/spring01/alias/applicationContext.xml");
HelloWorld helloWorld = (HelloWorld)context.getBean("狗蛋");
helloWorld.say();
2、 在文件系统路径下寻找配置文件来实例化容器
ApplicationContext ctx = new FileSystemXmlApplicationContext(new String[]{“d:\\beans.xml“});
Spring的配置文件可以指定多个,可以通过String数组传入。