我想使用RSSUtil来阅读RSS feed,但是我遇到了一个类加载器的问题……
抛出的异常是:
com.sun.syndication.feed.synd.SyndFeedImpl cannot be cast to com.sun.syndication.feed.synd.SyndFeedImpl我的代码是:
SyndFeedImpl feed = null;
final String _CLASS_NAME = "com.liferay.portlet.rss.util.RSSUtil";
MethodKey _CONSTRUCTOR = new MethodKey(_CLASS_NAME, "getFeed", String.class);
ObjectValuePair ovp = (ObjectValuePair) PortalClassInvoker.invoke(true, _CONSTRUCTOR, url);
Class<SyndFeed> clazz = (Class<SyndFeed>) PortalClassLoaderUtil.getClassLoader().loadClass(
"com.sun.syndication.feed.synd.SyndFeedImpl");
feed = (SyndFeedImpl) ovp.getValue();这个问题在https://www.liferay.com/fr/community/forums/-/message_boards/message/15812507中也有解释。我试着做同样的事情,但它不起作用...
提前感谢你的帮助……
更新:如果我使用下面的代码(没有RSSUtil的其他解决方案):
URL feedUrl = new URL(url);
HttpURLConnection httpcon = (HttpURLConnection) feedUrl.openConnection();
SyndFeedInput input = new SyndFeedInput();
XmlReader reader = new XmlReader(httpcon);
SyndFeed feed = input.build(reader);抛出的异常是:
java.lang.ClassCastException: com.sun.syndication.feed.synd.impl.ConverterForAtom10 cannot be cast to com.sun.syndication.feed.synd.Converter发布于 2015-03-18 00:29:00
我也遇到过同样的问题。我最终从liferayroot/tomcatxxx/webapps/ROOT/WEB-INF/lib复制了两个jars (dom4j.jar和rome.jar)到liferayroot/tomcatxxx/lib/ext
您得到的第一个错误是因为类是由不同的类加载器(门户类加载器和portlet类加载器)加载的。
尝试复制jars,应该可以
https://stackoverflow.com/questions/27911752
复制相似问题