Foren

What's the classloading model of Liferay

Jianyu Tang, geändert vor 11 Jahren.

What's the classloading model of Liferay

New Member Beiträge: 6 Beitrittsdatum: 15.02.12 Neueste Beiträge
Hi, when I develop liferay hook / plugins, sometime I have weird class loading issues like slf4j / log4j / spring jms template.

As Liferay will copy some jar files like util-java.jar when deploy some hook / plugin, can I know if Liferay following the standard JEE web app class loading pattern? You can refer this:

http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html

Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:

Bootstrap classes of your JVM
System class loader classes (described above)
/WEB-INF/classes of your web application
/WEB-INF/lib/*.jar of your web application
Common class loader classes (described above)

Thanks.
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: What's the classloading model of Liferay

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
Liferay does adhere to the app container's normal class loader hierarchy. The part that you're missing is the understanding of the context that your plugin operates...

Hooks actually apply themselves to the ROOT application context in some cases. For example, a JSP hook replaces the JSP files from ROOT w/ the copies that the hook provides. So at runtime, the JSP file is actually part of ROOT and not separately as part of your hook. This can lead to issues if you include a jar file in your Hook for your JSP because the JSP is now part of ROOT and has no visibility on whatever jar file you had included.

Long story short, you must be aware of how your hook functions at runtime and which web application it actually applies to (your hook's web app or ROOT's web app).
Jianyu Tang, geändert vor 11 Jahren.

RE: What's the classloading model of Liferay

New Member Beiträge: 6 Beitrittsdatum: 15.02.12 Neueste Beiträge
Thank you David. I do have lot of questions about the details, is there any documentation or book so I can learn?

I have spent quite some time to resolve an issue related to this. Can you explain how can I use a 3party library in my own hook? Actually It's spring-integration-jms, and trying to send a jms message from the audit-hook. But if I packaged spring-jms into the hook, I got below error:

Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframew
ork.jms.core.JmsTemplate' to required type 'org.springframework.jms.core.JmsTemplate' for property 'jmsTemplate'; nested excepti
on is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.jms.core.JmsTemplate] to required type
[org.springframework.jms.core.JmsTemplate] for property 'jmsTemplate': no matching editors or conversion strategy found

If I removed spring-jms out from the hook.war, I got:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'auditMessageSender' defined i
n ServletContext resource [/WEB-INF/classes/META-INF/audit-producer.xml]: Initialization of bean failed; nested exception is jav
a.lang.NoClassDefFoundError: org/springframework/jms/core/JmsTemplate

Neither error make sense to me. You can look at the original question from me below.

http://www.liferay.com/en/community/forums/-/message_boards/message/21880197
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: What's the classloading model of Liferay

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
Jianyu Tang:
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframew
ork.jms.core.JmsTemplate' to required type 'org.springframework.jms.core.JmsTemplate' for property 'jmsTemplate'; nested excepti
on is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.jms.core.JmsTemplate] to required type
[org.springframework.jms.core.JmsTemplate] for property 'jmsTemplate': no matching editors or conversion strategy found


This is an example of a class loading issue. Your hook has one context (where the classes are) but the code is invoked within the portal's context (where the classes aren't).

The good news is that this is resolved by using a correct architecture... The auditing system uses the Liferay Message Bus to publish auditing messages. Instead of trying to push to JMS directly as you are, instead create a listener on the destination of the LMB. In your listener, you can bridge from the LMB message to JMS. This will resolve your class loader issues while still allowing the publication to JMS.
harpreet singh, geändert vor 9 Jahren.

RE: What's the classloading model of Liferay

New Member Beiträge: 2 Beitrittsdatum: 22.09.14 Neueste Beiträge
David,

Am also having same issue, mine case is resttemplate from sprring
Cannot convert value of type [org.springframework.web.client.RestTemplate] to required type [org.springframework.web.client.RestTemplate] for property 'restTemplate': no matching editors or conversion strategy found

Please suggest
Umair Saleem, geändert vor 9 Jahren.

RE: What's the classloading model of Liferay

New Member Beiträge: 3 Beitrittsdatum: 10.02.15 Neueste Beiträge
Dears,

I am facing the same issue. Following is the stack trace

Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.springframework.jms.core.JmsTemplate] to required type [org.springframework.jms.core.JmsTemplate] for property 'myJmsTemplateObj': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:236)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:466)



I am also attaching the project with this post. Can you guys please point out what I am doing wrong and how to address this issue.

Thanks.
thumbnail
David H Nebinger, geändert vor 9 Jahren.

RE: What's the classloading model of Liferay

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
This really should have been posted to a new thread because no, it is not the same issue.

In your portal-dependency-jars you've only included the spring jars but none of the spring dependencies. Likely the hierarchy of the class in question is not resolvable due to a missing dependency class.
thumbnail
jelmer kuperus, geändert vor 11 Jahren.

RE: What's the classloading model of Liferay

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
I am not sure what the situation is like in liferay 6.1 and up but in 6.0.x liferay would use it's own spring PortletContextLoaderListener that is able to instantiate classes both portal classes (eg those in ROOT/WEB-INF/lib and classes) and hook classes (your-hook/WEB-INF/lib and classes) a problem arises when you have the same class in both classloaders (eg spring libraries) The easiest way to solve it would be to not use liferay's com.liferay.portal.kernel.spring.context.PortletContextLoaderListener but spring's org.springframework.web.context. ContextLoaderListener but in many cases this might not be an option and you'll need to come up with some sort of workaround
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: What's the classloading model of Liferay

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
Actually, Jelmer, in 6.1.1 PortletContextLoaderListener has been completely deprecated and now is just an empty implementation class (to facilitate deployment of older portlets which still have the reference in place).