gpt4 book ai didi

java - 调用 session.getWorkspace().getQuery() 会导致错误

转载 作者:行者123 更新时间:2023-11-30 04:34:07 24 4
gpt4 key购买 nike

我正在实现一个包含搜索服务(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

有人可以帮忙吗?提前致谢。

最佳答案

什么?

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

现在呢?

您有太多此 QueryManager 的副本在你的系统中,你需要要么去掉除一个之外的所有,或者确保选择正确的一个。第一个是最有可能发生的,第二个只有在您手动构建 bundle 时才可能发生。

QueryManager统治他们所有人

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

让一个包提供此类,并让它导出 ( and import! ) 包。

选择正确的

如果您确实出于充分原因拥有多份副本,请确保所有 bundle 都同意使用哪一份。请确保,

  • 当 bundle 导出 javax.jcr.query 时包,它也会导入它,因此解析器可以选择它认为最有用的一个,并且可以选择
  • 明确 javax.jcr.query 的副本当某些 bundle 使用 javax.jcr.query 时必须使用它。您可以通过放置 uses constraint 来做到这一点在您的导出中,尽管公平地说,您的工具应该自行完成此操作。

正如我上面所说,如果您需要诉诸此解决方案,您可能有手工制作的 bundle 。考虑使用类似 bndtools 的工具为您构建 bundle 。

关于java - 调用 session.getWorkspace().getQuery() 会导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13915190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com