今天写了个Factory Class,用来把interface和实现的class进行组合……以便在业务逻辑中调用……类似这样:
<managers>
<manager id="DbConnectionManager">
<service>tutorial.db.IDbConnectionManagerservice>
<service-impl>tutorial.db.impl.DbConnectionManagerImplservice-impl>
manager>
<manager id="EmployeeService">
<service>tutorial.service.iface.IEmployeeServiceservice>
<service-impl>tutorial.service.impl.EmployeeServiceImplservice-impl>
manager>
mamagers>
在业务逻辑中,类似下面的调用:
BizFactory bizFactory = new BizFactory();
Employee employee = new Employee();
employee.setEmpNumber("9527");
//...省略...
IEmployeeService empService
= (IEmployeeService) bizFactory.create("EmployeeService");
empService.update(employee);
但是在JBuilder运行的时候,却报告EmployeeServiceImpl.class找不到……郁闷……一看才发现,JBuilder 2005在Make的时候,在${PRoject_Home}/classes中生成了EmployeeServiceImpl.class文件,却并没有把这个文件部署到${Project_Home}/${WebModule_Home}/WEB-INF/classes下面!
分析了半天,难道是IEmployeeService有被显示调用,而EmployeeServiceImpl没有代码显示调用,是通过Factory Class读取config xml来创建的,难道……这就是要害???
翻了半天JBuilder 2005的配置选项,终于让我发现了……见下图,去掉那个默认的选项即可!
点击查看大图