从neo4j官方网站http://neo4j.org/下载neo4j-apoc包,或者自己获取源码自行打包也可。
我使用的是java开发工具是SpringToolSuite,新建一个springwebmvc项目,模板引擎使用velocity(velocity.apache.org),web.xml配置:
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="attentiondb"version="2.5">
<display-name>attentiondb</display-name>
<!--
EnablescleanURLswithJSPviewse.g./welcomeinsteadof
/app/welcome
-->
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--Handlesallrequestsintotheapplication-->
<servlet>
<servlet-name>SpringMVCDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/app-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVCDispatcherServlet</servlet-name>
<url-pattern>/attentiondb/*</url-pattern>
</servlet-mapping>
</web-app>
在/WEB-INF/spring/app-config.xml中配置neo4jbean(这里需要注意spring2.5与3.0的区别,3.0中使用map元素代替util:map元素):
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!--
Scanstheclasspathofthisapplicationfor@Componentstodeployas
beans
-->
<context:component-scanbase-package="attentiondb"/>
<beanid="graphDbService"class="org.neo4j.kernel.EmbeddedGraphDatabase"
init-method="enableRemoteShell"destroy-method="shutdown">
<constructor-argindex="0"value="d://attentiondb"/>
<constructor-argindex="1">
<map>
<entrykey="create"value="false"/>
<entrykey="neostore.nodestore.db.mapped_memory"value="20M"/>
<entrykey="neostore.propertystore.db.mapped_memory"value="90M"/>
<entrykey="neostore.nodestore.db.mapped_memory"value="1M"/>
<entrykey="neostore.nodestore.db.mapped_memory"value="1M"/>
<entrykey="neostore.nodestore.db.mapped_memory"value="130M"/>
<entrykey="neostore.nodestore.db.mapped_memory"value="100M"/>
</map>
</constructor-arg>
</bean>
<beanid="indexService"class="org.neo4j.index.lucene.LuceneIndexService"
destroy-method="shutdown">
<constructor-argindex="0"ref="graphDbService"/>
</bean>
<beanid="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<propertyname="resourceLoaderPath"value="/WEB-INF/views/"/>
</bean>
<beanid="viewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<propertyname="cache"value="true"/>
<propertyname="prefix"value=""/>
<propertyname="suffix"value=".vm"/>
</bean>
<!--ApplicationMessageBundle-->
<beanid="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<propertyname="basename"value="/WEB-INF/messages/messages"/>
<propertyname="cacheSeconds"value="0"/>
</bean>
<!--ConfiguresSpringMVC-->
<importresource="mvc-config.xml"/>
</beans>