标签:
spring的各个版本说明:
在3.0以下的版本,源码有spring中相关的所有包[spring功能+依赖包],如:2.5版本
在3.0以上的版本,源码中只有spring的核心功能包[没有依赖包],如果要用依赖包,需要单独下载!
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:p="http://www.springframework.org/schema/p" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xmlns:aop="http://www.springframework.org/schema/aop" 7 xmlns:tx="http://www.springframework.org/schema/tx" 8 xsi:schemaLocation=" 9 http://www.springframework.org/schema/beans 10 http://www.springframework.org/schema/beans/spring-beans.xsd 11 http://www.springframework.org/schema/context 12 http://www.springframework.org/schema/context/spring-context.xsd 13 http://www.springframework.org/schema/aop 14 http://www.springframework.org/schema/aop/spring-aop.xsd 15 http://www.springframework.org/schema/tx 16 http://www.springframework.org/schema/tx/spring-tx.xsd"> 17 18 <bean id="user" class="cn.fuyi.a_helloworld.User"></bean> 19 </beans>
1 public class App { 2 3 @Test 4 public void testIOC() { 5 Resource resource = new ClassPathResource("cn/fuyi/a_helloworld/ApplicationContext.xml"); 6 BeanFactory factory = new XmlBeanFactory(resource); 7 8 User user = (User) factory.getBean("user"); 9 System.out.println(user); 10 } 11 12 13 @Test 14 public void testAc() throws Exception { 15 ApplicationContext ac = new ClassPathXmlApplicationContext("cn/fuyi/a_helloworld/ApplicationContext.xml"); 16 17 User user = (User)ac.getBean("user"); 18 System.out.println(user); 19 } 20 21 }
标签:
原文地址:http://www.cnblogs.com/fuyiming/p/5824484.html