webdev
发贴: 9
|
于 2004-10-19 10:11
struts-config.xm配置 如下: <struts-config> ..........
<plug-in className="gxfc.service.news.impl.ArticleServiceFactoryImpl" /> <plug-in className="gxfc.service.user.impl.UserServiceFactoryImpl" /> </struts-config>
2个类是工厂类,分别生成2个对象的实例,代码如下:
public class ArticleServiceFactoryImpl implements IArticleServiceFactory, PlugIn { private ActionServlet servlet = null; String serviceClassname = "gxfc.service.news.impl.ArticleServiceImpl";
public IArticleService createService() throws ClassNotFoundException, IllegalAccessException, InstantiationException { String className = servlet.getInitParameter(IConstants. ARTICLESERVICE_CLASS_KEY);
if (className != null) { serviceClassname = className; }
try { IArticleService instance = (IArticleService) Class.forName(serviceClassname).newInstance(); instance.setServletContext(servlet.getServletContext()); return instance; } catch (Exception e) { e.printStackTrace(); return null; }
}
public void destroy() { /**@todo Implement this gxfc.service.news.IArticleServiceFactory method*/ throw new java.lang.UnsupportedOperationException( "Method destroy() not yet implemented."); }
public void init(ActionServlet servlet, ModuleConfig config) { this.servlet = servlet; servlet.getServletContext().setAttribute(IConstants. ARTICLESERVICE_FACTORY_KEY, this);
}
}
gxfc.service.news.impl.ArticleServiceFactoryImpl这个工厂运行是正常的,但是gxfc.service.user.impl.UserServiceFactoryImpl这个工厂无法生产出类的实例,后查明,发现是servlet这个变量为空的,也就是plug-in没有加载,但是代码都是一样,而且配置也是一样,为什么会一个加载了,另外一个没加载呢?
|