简体   繁体   English

使用Jersey和Tomcat将Spring Data Neo4j集成(Maven)在Dynamic Web Project中

[英]Integration (maven) of Spring Data Neo4j in Dynamic Web Project using Jersey and Tomcat

I´m getting a little bit lost in my own (maven enabled) dynamic WEB - Project. 我在自己的(启用Maven的)动态WEB-项目中迷失了一些。 The project works fine, I´ve got a RESTful WebService (Jersey) running and I´m able to consume it. 该项目运行良好,我正在运行RESTful WebService(Jersey),并且可以使用它。

... my next step was to persist my domain classes, with Spring Data and Neo4j. ...我的下一步是使用Spring Data和Neo4j保留我的域类。 So, I´ve added some tags to my pom.xml 因此,我在pom.xml中添加了一些标签

...
<repository>
  <id>spring-milestone</id>
  <name>Spring Maven MILESTONE Repository</name>
  <url>http://maven.springframework.org/milestone</url>
</repository>

<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-neo4j</artifactId>
  <version>2.0.0.RELEASE</version>
</dependency>
...

my next step was to annotate my entity-classes... here is a simple example: 我的下一步是注释我的实体类...这是一个简单的示例:

...
@NodeEntity
public class Category {

@GraphId Long nodeId;
String categoryType;

public Category(String categoryType){
    this.categoryType = categoryType;
}

}
...

okay, everything´s fine... now I want to persist my category-object... 好的,一切都很好...现在我要保留类别对象...

@Autowired Neo4jTemplate template;
@Test @Transactional 
public void toGraphDb() {

      template.save(new Category("mashineCategory"));
}   

when I run the test I´m getting a NullPointerException, cause the template is null 当我运行测试时,我得到一个NullPointerException,原因是模板为null

I guess there is something missing in my project, but I´m not sure in which folder/file to add informations/files... 我想我的项目中缺少一些东西,但是我不确定要在哪个文件夹/文件中添加信息/文件...

here is my web.xml: 这是我的web.xml:

...
<display-name>ElisaSimulatorM4</display-name>

<servlet>
  <servlet-name>Jersey REST Service</servlet-name>
   <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
  <param-name>com.sun.jersey.config.property.packages</param-name>
  <param-value>de.elisa.communication.webservice.restservice.implementation</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>


<servlet-mapping>
  <servlet-name>Jersey REST Service</servlet-name>
  <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
...

in some guides I read something about dispatcherServlets and an applicatonContext.xml, but I have no idea where to put it in my project. 在一些指南中,我阅读了有关dispatcherServlets和applicatonContext.xml的内容,但我不知道将其放在项目中的哪个位置。

Maybe someone can help me out... 也许有人可以帮我...

Ps. 附言 I wanted to upload a screenshot from my project-tree but as a greenhorn I haven't got enough reputation... sorry for that 我想从我的项目树中上传屏幕截图,但是作为新角,我没有足够的声誉...对此感到抱歉

Perhaps it is best to look into the supplied examples of Spring Data Neo4j http://spring.neo4j.org/examples there are some for simple projects like hello-world and some for more advanced web-applications cineasts. 也许最好看看提供的Spring Data Neo4j示例http://spring.neo4j.org/examples。有些示例适用于诸如hello-world之类的简单项目,有些适用于更高级的网络应用程序。

To get the idea the Spring Documentation about the general setup of a Spring(Web) application should help you. 要了解这个想法,有关Spring(Web)应用程序常规设置的Spring文档应该对您有所帮助。

You should probably start with a console application to get the ideas and then incorporate that in your web-application. 您可能应该从控制台应用程序开始以获取想法,然后将其合并到Web应用程序中。

The applicationContext.xml file is the SpringFramework configuration file. applicationContext.xml文件是SpringFramework配置文件。 It should be enough to have a minimal one, like this from the hello-world example. 像最小的hello-world示例中那样,最少要有一个就足够了。

Put it in src/main/resources/applicationContext.xml 将其放在src / main / resources / applicationContext.xml中

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <context:spring-configured/>
    <context:annotation-config/>

    <neo4j:config storeDirectory="path/to/db"/>
    <neo4j:repositories base-package="org.example.repository"/>

</beans>

Ran into the same issue after copying the sample code from Good Relationships and trying to "conjure the magic" of spring. 复制《良好关系》中的示例代码并尝试“唤起春天的魔力”后,遇到同样的问题。 AutoWiring is magic, but not quite magic enough without loading the class through Spring's application context. AutoWiring很神奇,但是如果没有通过Spring的应用程序上下文加载该类,就不够神奇了。 The following works for a standalone client. 以下适用于独立客户端。

    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("standaloneAppContext.xml");

    Test test = ctx.getBean(Test.class);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Eclipse中安装Maven集成后,如何创建一个使用Maven的动态Web项目(RESTful Jersey项目)? - After installed Maven integration in Eclipse, how to create a Dynamic Web Project (RESTful Jersey project) which use Maven? Spring Data Neo4j的命名空间错误 - Namespace error with spring data neo4j 在eclipse项目中使用neo4j数据库 - Using neo4j database in eclipse project 带有Maven集成的Eclipse动态Web项目 - Eclipse Dynamic Web Project with Maven Integration 使用Maven进行动态Web项目 - Using maven for a dynamic web project 在Android上使用Neo4j的问题 - Issues using Neo4j with Android 使用默认可视化在Web浏览器中可视化嵌入式neo4j实例 - Visualize an embedded neo4j instance in a web browser using default visualization spring-data-neo4j未将工作区目录用于storeDirectory - spring-data-neo4j not using workspace directory for storeDirectory 使用Maven + Eclipse + Tomcat开发jersey restfull Web服务。 404期 - developing jersey restfull web service using Maven + Eclipse + Tomcat. 404 issue 带有tomcat 7.0 eclipse插件的嵌入式neo4j数据库无法为Neo4j存储创建目录路径 - embedded neo4j database with tomcat 7.0 eclipse plugin Unable to create directory path for Neo4j store
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM