Apache Geronimo 中的依赖注入,第 2 部分: 下一代
2009-11-11 00:00:00 来源:WEB开发网清单 2 中的初始化代码是一个类的一部分,它使用 setter 注入进行 DI。在 本系列的第一篇文章 中,我把 setter 注入定义为容器(在这个示例中,是 Geronimo),在代码上调用 setXXX() 方法注入一些依赖属性值或类。为了方便这个 setter 注入,我为两个属性都注册了 set 方法。清单 3 显示了 Customer 类的完整清单。
清单 3. 可以进行 setter 注入的 Customer 类package com.nealford.articles.di_geronimo;
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class Customer implements GBeanLifecycle {
private static Log log = LogFactory.getLog(Customer.class);
private String name;
private double salary;
private static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(
Customer.class.getName(),
Customer.class);
// attributes
infoFactory.addAttribute("name", String.class, true);
infoFactory.addAttribute("salary", double.class, true);
infoFactory.addOperation("setName",
new Class[]{String.class});
infoFactory.addOperation("getName");
infoFactory.addOperation("setSalary",
new Class[] {double.class});
infoFactory.addOperation("getSalary");
GBEAN_INFO = infoFactory.getBeanInfo();
}
public void doStart() throws Exception {
log.info("Starting Customer GBean");
}
public void doStop() throws Exception {
log.info("Stopping Customer GBean");
}
public void doFail() {
log.info("customer GBean failure!");
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(final double salary) {
this.salary = salary;
}
}
- ››apache设置域名绑定 以及绑定不起作用的排查
- ››apache rewrite将指定URL转向指定的几个服务器
- ››apache配置文件httpd.comf部分参数说明
- ››Apache+Mysql+PHP+phpMyAdmin+Mac OS X 10.7 Lion...
- ››apache+tomcat负载均衡_项目实例
- ››apache mysql php 源码编译使用
- ››Apache添加mod_aspdotnet.so支持ASP.NET配置指南
- ››Apache中改变php.ini的路径
- ››Apache2.2与Tomcat6整合及虚拟主机配置
- ››Apache+php+mysql在windows下的安装与配置图解
- ››Apache+Subversion完美结合,CentOS下实现版本控制...
- ››Apache HTTPServer2.2.16 发布
更多精彩
赞助商链接