2013-01-16 42 views
5

一個教程how to embed Neo4j in a java application建議註冊一個關閉掛鉤,像這樣:在Spring 3中註冊關閉鉤子的正確方法是什麼?

Runtime.getRuntime().addShutdownHook(new Thread() { 
    // do shutdown work here 
}); 

我想知道最好的地方,把這個代碼 - 其實還是需要運行一次春季開始時的任何代碼。它只是一個registering a bean with an init method的案例,並把代碼放在那裏?

我很想知道這一點,更具體地說,在Spring應用程序中使用嵌入式Neo4j時,其他人是如何註冊關閉鉤子的。

回答

8

只是用正確的destroy-method聲明你的圖數據庫服務豆:

<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" 
     destroy-method="shutdown"> 
    <constructor-arg index="0" value="data/testdb.db"/> 
    <constructor-arg index="1"> 
     <map> 
      <entry key="allow_store_upgrade" value="true"/> 
     </map> 
    </constructor-arg> 
</bean> 
+0

你有這樣的註解配置嗎? – chrisjleu

+0

@Bean public GraphDatabaseService graphDatabaseService(){return new EmbeddedGraphDatabase(storeDir,config); } –

+1

@Bean(destroyMethod =「shutdown」)public GraphDatabaseService graphDatabaseService(){return new EmbeddedGraphDatabase(storeDir,config); } – zebeurton

-3

使用1.8.1的Neo4j和SDN 2.1 - 上面沒有我的Eclipse /碼頭的環境中工作。

幾乎每一個我開始/停止時間與Eclipse的「服務器」的控制,我認爲這對啓動:

信息:對數檢測非正常關機......

注:我沒有設置儘管「allow-store-upgrade」屬性。我認爲這與乾淨關機無關?

相關問題