要在多个portlet之间共享的Singleton类 [英] Singleton class to be shared among multiple portlets

查看:75
本文介绍了要在多个portlet之间共享的Singleton类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Liferay应用程序中有几个Singleton类,它们包含几个配置参数,ServiceLocator包含我需要使用的Web服务实例。

I have a couple of Singleton classes in a Liferay application that hold several configuration parameters and a ServiceLocator with instances to WebServices I need to consume.

我放了这些jar中的类,声明为对所有portlet的依赖。

I have put these classes in a jar that is declared as a dependency on all my portlets.

问题是,我已经在这些单例类中放置了一些日志记录行进行初始化,当我部署我的portlet时,我可以多次看到这些行,每个portlet一次,因为每个portlet都有自己的类上下文。

The thing is, I have put some logging lines for initialization in theses singleton classes, and when I deploy my portlets I can see these lines multiple times, once for every portlet, since each portlet has its own class context.

对于AppConfig类,它可能不是什么大问题,但我的ServiceLocator实际上确实持有一堆引用很好的内存。

For the AppConfig class it might not be such a big deal but my ServiceLocator does actually hold a bunch of references that take a good bit of memory.

我有没有办法将这些Singleton引用放在Liferay Portal中的某种共享上下文中?

Is there any way that I can put these Singleton references in some kind of Shared context in my Liferay Portal?

推荐答案

问题是每个Portlet都在自己的WAR文件中运行,而aech war文件有自己的类加载器。

The problem is that every Portlet runs in its own WAR file and aech war file has its own classloader.

通常当我必须达到这样的要求时,我不得不将Singleton classen放在一个JAR文件中,并将这个JAR文件放在公共类加载器库中而不是打包它进入每个WAR。 (在Tomcat:< tomcatHome> / common / lib 或类似的东西)

Usually when I had to achieve a requirement like this, I had to put the Singleton classen in a JAR file and this JAR file in the common class loader library instead of packing it into each WAR. (In Tomcat: <tomcatHome>/common/lib or something like that)

然后你也会必须将所有依赖库放入该公共lib目录中。但是,不知道如何在Liferay中做到这一点。对于tomcat,请参阅以下主题:stackoverflow.com/questions/267953/和本文档: http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html 。取决于Servlet容器。

Then you'll also have to put all dependent libraries into that common lib dir, too. Don't know how to do that in Liferay, though. For tomcat see this thread: stackoverflow.com/questions/267953/ and this documentation: http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html. Depends on the Servlet container.

这篇关于要在多个portlet之间共享的Singleton类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆