Spring
文章平均质量分 78
czjuttsw
Learning, staying up to date, and working on the latest and greatest in languages and APIs is what keeps me excited.
展开
-
构造方法注入
一:新建Java工程-SpringDemo 二:导入Spring jar包和commons-logging jar包。 项目结构: 三:编写bean public class UserBean { private String name; private long age; private String address; public U原创 2013-03-31 21:05:31 · 1529 阅读 · 0 评论 -
Setter Injection
在bean中通过提供属性的setter方法,在Spring配置文件中进行注入。实现了一定的松耦合。 步骤一:新建Java工程-SpringDemo。 步骤二:导入Spring JAR包和commons-logging JAR包。 步骤三:编写bean public class Animal { private String category; private String原创 2013-04-01 21:59:23 · 1399 阅读 · 0 评论 -
Spring AOP 初探
AOP: Aspect Oriented Programming 面向切面编程。 面向切面编程(也叫面向方面编程):Aspect Oriented Programming(AOP),是目前软件开发中的一个热点,也是Spring框架中的一个重要内容。利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率。 AOP是OO原创 2013-04-02 15:01:17 · 1522 阅读 · 1 评论 -
Spring Singleton VS prototype
在Spring中,bean的作用域范围有5种,它们是[singleton,prototype,request,session,globalSession],其中singleton是默认值。 在大多数情况下,我们只和singleton和prototype打交道。那么,它们之间有什么区别呢? singleton: 如单例模式一样,调用getBean()方法试图从IoC容器中返回唯一原创 2013-04-03 15:36:51 · 1965 阅读 · 0 评论 -
Spring 集合注入 [ Collection Injection ]
对于简单数据类型(byte,char,short,int,float,double,long )或者String的注入,一般只需写入标签即可。比如: 或者 simpleValue 或者p模式 如果需要注入的是集合(list,set,map,pros),那该怎么做呢? 如果集合的泛型是简单数据类型,比如 List,可以这样实现: stu原创 2013-04-03 13:11:01 · 2735 阅读 · 0 评论 -
Spring Bean 生命周期 三种表示方法
文章的索引: 通过接口InitializingBean,DisposableBean实现Bean生命周期。通过JavaEE注解@PostConstruct,@PreDestroy实现Bean生命周期。通过配置文件标签属性init-method和destroy-method实现Bean生命周期。 因为演示的需要,首先给出一个普通的bean: public class SimpleBean原创 2013-04-05 12:31:21 · 2083 阅读 · 0 评论 -
Spring bean 实现生命周期的三种解决方案
解决方案一:通过XML配置文件实现:(标签bean的属性init-method和destroy-method) beans.xml: SimpleBean.java: package org.spring.tutorial; public class SimpleBean { public SimpleBean() { System.out.println("SimpleBe原创 2013-05-19 18:03:02 · 1866 阅读 · 0 评论 -
Spring集合注入
Spring提供了4种类型的集合,分别是list,set,map,props。 list和set都可用于数组和集合类,包括List,Set和Vector。 需要注意的是,如果注入的类型和配置文件中有一个是set类型,那么注入的值中肯定是无重复的。 map和props对应于JDK的Map和Properties。它们是键值对的集合。map和props的区别是,map的键值类型是object,而p原创 2013-05-30 18:51:25 · 1536 阅读 · 0 评论