Spring Data Neo4j:使用带有嵌入式的 Neo4j 服务器:JAR 包装 [英] Spring Data Neo4j: using the Neo4j server with an embedded: JAR packaging

查看:32
本文介绍了Spring Data Neo4j:使用带有嵌入式的 Neo4j 服务器:JAR 包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于能够在我的 java 应用程序中创建一个使用嵌入式数据库的服务器实例,如 但我不清楚答案.

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

解决方案

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

<块引用>

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

所以在我的 pom 中添加这个转换器是有效的,例如:

...<构建><插件><插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>2.0</version><执行><执行><phase>包</phase><目标><目标>阴影</目标></目标><配置><变形金刚><transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/></变形金刚></配置></执行></执行></插件></插件></build>...</项目>

希望能帮到你!

I was finally able to create a server instance within my java app that uses the embedded database as explained here. This works properly while I'm running it from Eclipse, but this is not actually my purpose (my app, between other things, feeds the database with new nodes and relationships). I have a Neo4j box which is supposed to be my server instance and I want to deploy my app there as a JAR file. In that way, I would like to access the web interface from there. I have already tested it: while running the java app in my development machine any machine in the same private network can access the interface without problems. The issue comes when trying to package everything into a JAR for server distribution.

The concrete error stack is as follows:

<!-- 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

I must say I'm pretty new to Spring, Maven and Neo4j itself. I'm quite lost how to get rid of this issue. The web interface actually loads but without any kind of functionality. See attached shot:

.

The backend of my app works fine despite of this issue and actually new nodes/relationships are created.

I think this issue (or kind of) was discussed here but the answer is not clear to me.

Any suggestions? Thank you in advance!

解决方案

I finally found a solution, which did the trick. I just share it, in case anyone else experiences the same issue. The problem was that some files under META-INF/services were being overwritten during the jar packaging process, since by default their content is not merged. According to the maven-shade plugin reference:

JAR files providing implementations of some interfaces often ship with a META-INF/services/ directory that maps interfaces to their implementation classes for lookup by the service locator. To merge multiple implementations of the same interface into one service entry, the ServicesResourceTransformer can be used.

So adding this transformer in my pom just worked, e.g.:

<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>

Hope it helps!

这篇关于Spring Data Neo4j:使用带有嵌入式的 Neo4j 服务器:JAR 包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆