フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Jianyu Tang
What's the classloading model of Liferay
2013/03/12 1:35
答え

Jianyu Tang

ランク: New Member

投稿: 6

参加年月日: 2012/02/15

最近の投稿

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.
David H Nebinger
RE: What's the classloading model of Liferay
2013/03/12 5:25
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 11511

参加年月日: 2006/09/01

最近の投稿

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
RE: What's the classloading model of Liferay
2013/03/19 3:40
答え

Jianyu Tang

ランク: New Member

投稿: 6

参加年月日: 2012/02/15

最近の投稿

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
David H Nebinger
RE: What's the classloading model of Liferay
2013/03/19 6:36
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 11511

参加年月日: 2006/09/01

最近の投稿

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.
Jelmer Kuperus
RE: What's the classloading model of Liferay
2013/03/19 7:35
答え

Jelmer Kuperus

ランク: Liferay Legend

投稿: 1192

参加年月日: 2010/03/10

最近の投稿

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
David H Nebinger
RE: What's the classloading model of Liferay
2013/03/19 9:46
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 11511

参加年月日: 2006/09/01

最近の投稿

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).
harpreet singh
RE: What's the classloading model of Liferay
2014/10/13 5:11
答え

harpreet singh

ランク: New Member

投稿: 2

参加年月日: 2014/09/22

最近の投稿

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
RE: What's the classloading model of Liferay
2015/02/25 5:12
答え

Umair Saleem

ランク: New Member

投稿: 3

参加年月日: 2015/02/10

最近の投稿

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.
添付ファイル: testMq-portlet.zip (87.2k)
David H Nebinger
RE: What's the classloading model of Liferay
2015/02/25 6:02
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 11511

参加年月日: 2006/09/01

最近の投稿

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.