摘要: 4.1 Spring IoC容器和bean的介绍 IoC也被称为是依赖注入(DI)。先构造对象,设置属性等,然后容器在bean的时候注入那些依赖,控制反转(IoC)。 Bean本身控制实例化或直接地使用类的构造来定位它的依赖,或者是如服务定位器模式的机制。 org.springframework.beans和org.springframework.context包是Spring Framework的IoC容器的基础。BeanFactory接口提供高级的配置机制,可以管理任意类型的对象。ApplicationContext是BeanFactory的子接口。它添加了和Spring的AOP特性... 阅读全文
posted @ 2013-04-19 17:02 跳刀的兔子 阅读(635) 评论(0) 推荐(0) 编辑
摘要: 加载文件顺序情形一:使用classpath加载且不含通配符这是最简单的情形,Spring默认会使用当前线程的ClassLoader的getResource方法获取资源的URL,如果无法获得当前线程的ClassLoader,Spring将使用加载类org.springframework.util.ClassUtils的ClassLoader。1.当工程目录结构如图所示: ApplicationContext context =new ClassPathXmlApplicationContext("conf/application-context.xml");加载[conf/a 阅读全文
posted @ 2013-04-19 03:51 跳刀的兔子 阅读(16129) 评论(0) 推荐(1) 编辑
摘要: 使用场景: 根据配置路径自动加载符合路径规则的xml文件、类文件等等; 查找范围:当前工程,当前工程依赖的jar包;示例:public void testGetResources(){ ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); try { Resource[] metaInfResources = resourcePatternResolver .getResources("classpath*:**/*DA... 阅读全文
posted @ 2013-04-19 03:18 跳刀的兔子 阅读(16353) 评论(0) 推荐(2) 编辑