Singleton class to be shared among multiple portlets

后端 未结 3 939
广开言路
广开言路 2021-01-06 20:24

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

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 20:50

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

    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: /common/lib or something like that)

    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.

提交回复
热议问题