当前位置: 首页 > 知识库问答 >
问题:

Spring数据Neo4j:使用带有嵌入式:JAR包的Neo4j服务器

郁吉星
2023-03-14

我终于能够在我的java应用程序中创建一个服务器实例,使用html" target="_blank">嵌入式数据库,如下所述。当我在Eclipse上运行它时,它可以正常工作,但这实际上不是我的目的(我的应用程序在其他事情之间,为数据库提供新的节点和关系)。我有一个Neo4j盒子,它应该是我的服务器实例,我想把我的应用程序作为JAR文件部署在那里。这样,我想从那里访问web界面。我已经对它进行了测试:在我的开发机器上运行java应用程序时,同一个专用网络中的任何机器都可以毫无问题地访问该接口。当试图将所有内容打包到一个JAR中以供服务器分发时,就会出现问题。

具体错误堆栈如下所示:

<!-- bean initialization stuff -->

Apr 11, 2013 1:14:30 PM org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLog doInternalRecovery
INFO: Non clean shutdown detected on log [/data/production/graph.db/nioneo_logical.log.2]. Recovery started ...
Apr 11, 2013 1:14:32 PM org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLog doInternalRecovery
INFO: Non clean shutdown detected on log [/data/production/graph.db/index/lucene.log.2]. Recovery started ...
2013-04-11 13:14:34,787 INFO [org.springframework.transaction.jta.JtaTransactionManager] - Using JTA UserTransaction: org.neo4j.kernel.impl.transaction.UserTransactionImpl@1b2fde11
2013-04-11 13:14:34,787 INFO [org.springframework.transaction.jta.JtaTransactionManager] - Using JTA TransactionManager: org.neo4j.kernel.impl.transaction.SpringTransactionManager@639c3c08
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log
INFO: Starting Neo Server on port [7474] with [40] threads available
Logger not configured, logging to std out instead: [FINE] Adding JAXRS packages [org.neo4j.server.rest.discovery] at [/]
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log
INFO: Mounted discovery module at [/]
Logger not configured, logging to std out instead: [FINE] Adding JAXRS packages [org.neo4j.server.rest.web] at [/db/data]
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log
INFO: Mounted REST API at [/db/data]
Logger not configured, logging to std out instead: [FINE] Adding JAXRS packages [org.neo4j.server.webadmin.rest] at [/db/manage]
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log
INFO: Mounted management API at [/db/manage]
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log
INFO: Mounted webadmin at [/webadmin]
2013-04-11 13:14:35,494 INFO [org.mortbay.log] - Logging to org.slf4j.impl.Log4jLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log
INFO: Mounting static content at [/webadmin] from [webadmin-html]
Logger not configured, logging to std out instead: [FINE] Found [jar:file:/home/jaranda/cicerone/cicerone-crawlers/target/cicerone-crawlers-0.0.1-SNAPSHOT.jar!/webadmin-html]
Logger not configured, logging to std out instead: [FINE] Mounting static content from [jar:file:/home/jaranda/cicerone/cicerone-crawlers/target/cicerone-crawlers-0.0.1-SNAPSHOT.jar!/webadmin-html] at [/webadmin]
Logger not configured, logging to std out instead: [FINE] Mounting servlet at [/db/manage]
Logger not configured, logging to std out instead: [FINE] Mounting servlet at [/db/data]
Logger not configured, logging to std out instead: [FINE] Mounting servlet at [/]
2013-04-11 13:14:35,556 INFO [org.mortbay.log] - jetty-6.1.x
2013-04-11 13:14:35,915 INFO [org.mortbay.log] - NO JSP Support for /webadmin, did not find org.apache.jasper.servlet.JspServlet
Apr 11, 2013 1:14:36 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  org.neo4j.server.webadmin.rest
Apr 11, 2013 1:14:39 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class org.neo4j.server.webadmin.rest.JmxService
  class org.neo4j.server.webadmin.rest.ConsoleService
  class org.neo4j.server.webadmin.rest.MonitorService
  class org.neo4j.server.webadmin.rest.RootService
Apr 11, 2013 1:14:39 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Apr 11, 2013 1:14:39 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.9 09/02/2011 11:17 AM'
Apr 11, 2013 1:14:40 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  org.neo4j.server.rest.web
Apr 11, 2013 1:14:43 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class org.neo4j.server.rest.web.ResourcesService
  class org.neo4j.server.rest.web.RestfulGraphDatabase
  class org.neo4j.server.rest.web.DatabaseMetadataService
  class org.neo4j.server.rest.web.ExtensionService
  class org.neo4j.server.rest.web.CypherService
  class org.neo4j.server.rest.web.BatchOperationService
Apr 11, 2013 1:14:43 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Apr 11, 2013 1:14:43 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.9 09/02/2011 11:17 AM'
Apr 11, 2013 1:14:43 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  org.neo4j.server.rest.discovery
Apr 11, 2013 1:14:46 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class org.neo4j.server.rest.discovery.DiscoveryService
Apr 11, 2013 1:14:46 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Apr 11, 2013 1:14:46 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.9 09/02/2011 11:17 AM'
2013-04-11 13:14:46,751 INFO [org.mortbay.log] - Started SelectChannelConnector@172.20.100.33:7474
Apr 11, 2013 1:14:46 PM org.neo4j.server.logging.Logger log
INFO: Server started on [http://172.20.100.33:7474/]
2013-04-11 13:14:47,616 INFO [org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler] - Initializing ExecutorService  'taskScheduler'
2013-04-11 13:14:47,714 INFO [com.twitter.hbc.httpclient.BasicClient] - New connection executed: Hosebird-Client-02, endpoint: /1.1/statuses/filter.json?delimited=length&stall_warnings=true
2013-04-11 13:14:48,346 INFO [com.twitter.hbc.httpclient.ClientBase] - Hosebird-Client-02 Establishing a connection
Apr 11, 2013 1:14:48 PM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: A message body writer for Java class [B, and Java type class [B, and MIME media type application/json was not found
Apr 11, 2013 1:14:48 PM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: The registered message body writers compatible with the MIME media type are:
*/* ->
  com.sun.jersey.server.impl.template.ViewableMessageBodyWriter

Apr 11, 2013 1:14:48 PM com.sun.jersey.spi.container.ContainerResponse logException
SEVERE: Mapped exception to response: 500 (Internal Server Error)
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class [B, and Java type class [B, and MIME media type application/json was not found
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:285)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
    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.HandlerCollection.handle(HandlerCollection.java:114)
    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: com.sun.jersey.api.MessageException: A message body writer for Java class [B, and Java type class [B, and MIME media type application/json was not found
    ... 22 more

我必须说我对Spring,Maven和Neo4j本身非常陌生。我不知道如何解决这个问题。网页界面实际上加载,但没有任何功能。见附加镜头:

我的应用程序的后端工作正常,尽管这个问题,实际上新的节点/关系被创建。

我认为这个问题(或某种程度上)已经在这里讨论过了,但我不清楚答案。

有什么建议吗?提前谢谢你!

共有1个答案

姬阳曜
2023-03-14

我终于找到了一个解决办法,成功了。我只是分享一下,以防其他人也遇到同样的问题。问题是META-INF/services下的一些文件在jar打包过程中被覆盖,因为默认情况下它们的内容不会合并。根据maven shade插件参考:

提供某些接口实现的JAR文件通常附带META-INF/services/目录,该目录将接口映射到它们的实现类,以供服务定位器查找。要将同一接口的多个实现合并到一个服务条目中,可以使用ServicesResourceTransformer。

因此,在我的pom中添加此变压器刚刚起作用,例如:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

希望有帮助!

 类似资料:
  • 我正在尝试配置我的应用程序上下文,以便能够在我的应用程序中使用带有嵌入式图形的Neo4j服务器,但没有多大成功。我同时使用Spring数据(Mongo和Neo4j存储库方法)。这是我的应用程序上下文,未运行: 如果我不使用这种方法,只指定存储目录(注释行),那么一切都可以正常运行。我怀疑这是SDN和neo4j服务器之间的版本问题。这是我的POM: 它的父项作为依赖项Spring(核心、上下文、测试

  • Neo4j 2.0。0已发布。所以我更新了neo4j版本2.0。0.M6到2.0。0.0发布。并尝试在我的网站中更新模型,但出现异常。 组织。springframework。刀。DataIntegrityViolationException:唯一属性类java。lang.String rankStatId rel:false idx:true被设置为重复值3073631_99 MY SDN版本是2

  • 我想用Spring构建一个RESTful应用程序,使用Neo4j作为数据库。我(非常简单地)想要的是一个应用程序,它通过POST获取实体(如用户),将它们保存在Neo4j数据库中,并将它们加载到GET上。 为此,我尝试了spring教程(构建嵌入式graphdb,并通过rest访问外部graphdb),效果不错,但我似乎无法使用neo4j单机版实时查看数据库,因为它似乎被我的应用程序锁定。 对我来

  • 我在我的脚手架上工作,我似乎无法让尼奥嵌入初始化。我使用Neo 2,所以我运行Spring数据3.0.0. m1。我不能让它亮起来。这是我的背景 但我有个例外 我找不到任何地方说有更多的构造函数参数。 这是我的依赖项

  • 我正在构建一个将使用neo4j的web应用程序。我将在Java构建一个REST API,它将使用Neo4j嵌入式版本。这个架构有什么问题吗? 用别的方法好吗?Neo4j服务器? 谢谢!

  • 我有一个neo4j嵌入应用程序与Spring启动实现。 我需要可视化我的图形并执行一些密码查询。 对我来说,完美的解决方案是在不启动neo4j服务器的情况下在某处部署webadmin界面,并将webadmin链接到我的数据文件夹。 这有可能吗? 提前谢谢。当做