Topic: plug-in只能加载一个类的实例的问题

  Print this page

1.plug-in只能加载一个类的实例的问题 Copy to clipboard
Posted by: webdev
Posted on: 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没有加载,但是代码都是一样,而且配置也是一样,为什么会一个加载了,另外一个没加载呢?


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923