2012-01-23 11 views
0

私自身(maven対応)動的WEBプロジェクトで少し失われています。プロジェクトは正常に動作し、私はRESTful WebService(Jersey)を実行しており、それを消費することができます。JerseyとTomcatを使用したDynamic Web ProjectでのSpring Data Neo4jの統合(maven)

...私の次のステップは、SpringデータとNeo4jを使用してドメインクラスを永続化することでした。

... 
@NodeEntity 
public class Category { 

@GraphId Long nodeId; 
String categoryType; 

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

} 
... 

大丈夫、everything':だから、I'veは私の次のステップは私のエンティティクラスに注釈を付けた

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

私のpom.xmlにいくつかのタグを追加...ここに簡単な例であります私はNullPointerExceptionが取得テスト - 私を実行すると

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

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

、テンプレートがnullの原因...罰金は...今私は、カテゴリ・オブジェクトを永続化したいよ

私はそこに私のプロジェクトでは不足している何かがあるが、情報/ファイルを追加したフォルダ/ファイルに - 私はわからない...ここ

は私の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

ありがとうDave!私はいくつかの情報を追加しました – Gerd

+0

設定ファイルのように、どこにでも挿入するテンプレートを定義していますか? –

答えて

1

おそらく、Spring Data Neo4j http://spring.neo4j.org/examplesの提供された例を見るのが一番ですこんにちは世界のような単純なプロジェクトのためのものと、高度なWebアプリケーションのためのものです。

Spring(Web)アプリケーションの一般的な設定については、Spring Documentationというアイデアを参考にしてください。

あなたは、コンソールアプリケーションからアイデアを取得し、それをあなたのWebアプリケーションに組み込む必要があります。

applicationContext.xmlファイルは、SpringFramework構成ファイルです。こんにちは世界の例のように、最小限のものがあれば十分です。

の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

それを入れては良好な関係からのサンプルコードをコピーし、春の「魔法を想起させる」しようとした後、同じ問題に遭遇しました。自動ワイヤリングは魔法ですが、Springのアプリケーションコンテキストを通してクラスをロードすることなく、十分に魔法ではありません。スタンドアロンクライアントでは次のように動作します。

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

    Test test = ctx.getBean(Test.class); 
関連する問題