1

我正在实现一个包含搜索服务(AbstractService)的 osgi 包。该服务包含一个获取内容节点列表作为 NodeIterator 对象的方法。

 public NodeIterator getNodes(Session session, String query, long count) throws RepositoryException{
            NodeIterator nodeIterator = null;

            QueryManager queryManager = session.getWorkspace().getQueryManager();

            Query qry = queryManager.createQuery(query, Query.SQL);
            qry.setLimit(count);
            QueryResult result = qry.execute();
            nodeIterator = result.getNodes();


        return nodeIterator;
    }

我有一个错误在线:

QueryManager queryManager = session.getWorkspace().getQueryManager();

错误

org.apache.sling.api.SlingException: An exception occurred processing JSP page /apps/IMEApp/Content/Category/../../General/html_marketCommentary.jsp at line 49
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:571)
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:496)
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:442)
    at org.apache.sling.scripting.jsp.JspServletWrapperAdapter.service(JspServletWrapperAdapter.java:59)
    at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:173)
    at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:84)
    at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:388)
    at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:358)
    at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:170)
    at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:456)
    at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:529)
    at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:274)
    at org.apache.sling.engine.impl.filter.RequestSlingFilterChain.render(RequestSlingFilterChain.java:49)
    at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)
    at org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter.doFilter(RequestProgressTrackerLogFilter.java:59)
    at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
    at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processRequest(SlingRequestProcessorImpl.java:161)
    at org.apache.sling.engine.impl.SlingMainServlet.service(SlingMainServlet.java:183)
    at org.apache.felix.http.base.internal.handler.ServletHandler.doHandle(ServletHandler.java:96)
    at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:79)
    at org.apache.felix.http.base.internal.dispatch.ServletPipeline.handle(ServletPipeline.java:42)
    at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:49)
    at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
    at org.apache.felix.http.base.internal.dispatch.FilterPipeline.dispatch(FilterPipeline.java:48)
    at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:39)
    at org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherServlet.java:67)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:926)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.jcr.Workspace.getQueryManager()Ljavax/jcr/query/QueryManager;" the class loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoaderJava5) of the current class, org/dapa/ime/service/AbstractService, and the class loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoaderJava5) for resolved class, javax/jcr/Workspace, have different Class objects for the type javax/jcr/query/QueryManager used in the signature
    at org.dapa.ime.service.AbstractService.getNodes(AbstractService.java:43)
    at org.dapa.ime.service.NewsService.getListOfNews(NewsService.java:35)
    at org.dapa.ime.service.NewsService.getListOfTopNews(NewsService.java:57)
    at org.apache.jsp.apps.IMEApp.Content.Category.html_jsp._jspService(html_jsp.java:1995)
    at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    ... 37 more

我无法理解由部分引起的:

Caused by: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.jcr.Workspace.getQueryManager()Ljavax/jcr/query/QueryManager;" the class loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoaderJava5) of the current class, org/dapa/ime/service/AbstractService, and the class loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoaderJava5) for resolved class, javax/jcr/Workspace, have different Class objects for the type javax/jcr/query/QueryManager used in the signature

任何身体都可以帮忙吗?提前致谢。

4

1 回答 1

2

什么?

这种ALinkageError通常是由不完整的 OSGi 元数据引起的:在当前情况下,您允许两个捆绑包(一个正在加载AbstractService,一个正在加载Workspace)具有不同版本的QueryManager.

现在?

您的系统中有太多的副本QueryManager,您需要删除除一个以外的所有副本,或者确保选择正确的副本。第一个最有可能发生,第二个只有在您手动构建捆绑包时才可能发生。

一统QueryManager天下

检查多个捆绑包是否包含此类。我不知道你如何构建你的包,但你可能有一些过于雄心勃勃的工具将类放入需要它的每个包中。一个常见的原因是<Embed-Transitive>true</Embed-Transitive>在您的 Maven POM 中使用。

让一个包提供这个类,并让它导出(和导入!)包。

选择正确的

如果您确实有多个副本,请确保所有捆绑包都同意使用哪一个。确保,

  • 当一个包导出javax.jcr.query包时,它也会导入它,因此解析器可以选择它认为最有用的一个,并且可以选择
  • 明确说明javax.jcr.query某些捆绑使用时必须使用的副本javax.jcr.query。您可以通过对导出设置uses约束来做到这一点,但公平地说,您的工具应该自己做到这一点。

如上所述,如果您需要使用此解决方案,您可能拥有手工制作的捆绑包。考虑使用像bndtools这样的工具来为你构建你的包。

于 2012-12-17T15:55:44.507 回答