2012-01-23 17 views
0

在我自己的(啓用maven的)動態WEB-Project中,我有點迷失了方向。該項目工作正常,我有一個RESTful WebService(澤西島)運行,我可以消耗它。動態Web項目中使用Jersey和Tomcat集成(maven)Spring Data Neo4j

...我的下一步是堅持我的域類,Spring Data和Neo4j。所以,從來就增加了一些標籤到我的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> 
... 

我的下一步是標註我的實體類...這裏是一個簡單的例子:

... 
@NodeEntity 
public class Category { 

@GraphId Long nodeId; 
String categoryType; 

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

} 
... 

沒關係,everything'沒事......現在我要堅持我的類對象...

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

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

當我運行測試I'm得到一個NullPointerException異常,導致模板是空

我想有東西在我的項目中失蹤,但我不確定在哪個文件夾/文件添加信息/文件...

這裏是我的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> 
... 

在一些指南,我讀了一些關於dispatcherServlets和一個applicatonContext.xml,但我不知道把它放在我的項目中。

也許有人可以幫助我...

Ps。我想從我的項目樹上傳截圖,但作爲一個新手我沒有足夠的聲譽...對不起,

+1

這可能有助於包括你得到的異常(只是相關部分)。否則,我們無法診斷任何東西。 –

+0

感謝戴夫!我添加了一些信息 – Gerd

+0

你是否定義了一個模板來注入任何地方,比如在配置文件中? –

回答

1

也許最好看看Spring Data提供的例子Neo4j http://spring.neo4j.org/examples還有一些對於像hello-world這樣的簡單項目和一些用於更高級的web應用程序的cineasts。

想要了解關於Spring(Web)應用程序的一般設置的Spring Documentation應該對您有所幫助。

您應該先從控制檯應用程序中獲取想法,然後將其融入到您的Web應用程序中。

applicationContext.xml文件是SpringFramework配置文件。從hello-world示例中獲得最小值應該足夠了。

把它放在src /主/資源/ 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> 
+0

嗨邁克爾,它是理解春季框架真正的一個普遍問題。我在玩tinkerpop框架的最後幾周。我也將在下週進一步深入Spring Data Neo4j。我會將這個問題標記爲已解決。 – Gerd

0

遇到同樣的問題,從複製良好人際關係的示例代碼,並試圖「召喚魔法」春天之後。 AutoWiring是神奇的,但如果不通過Spring的應用程序上下文加載類,它就不夠神奇。以下適用於獨立客戶端。

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

    Test test = ctx.getBean(Test.class); 
相關問題