下拉镜像

docker pull neo4j

启动镜像

docker run -d -p 7473:7473 -p 7687:7687 -p 7474:7474 neo4j

打开浏览器:http://192.168.31.146:7474/browser/

用户名/密码初始值为:neo4j

首次登陆需要修改密码

登陆后界面

新建springboot项目,添加pom引用

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.voodoodyne.jackson.jsog/jackson-jsog -->
<dependency>
<groupId>com.voodoodyne.jackson.jsog</groupId>
<artifactId>jackson-jsog</artifactId>
<version>1.1.</version>
</dependency>

添加Actor类

package org.mythsky.neo4jdemo;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity; @JsonIdentityInfo(generator = JSOGGenerator.class)
@NodeEntity
public class Actor {
@GraphId Long id;
private String name;
private int born; public Long getId() {
return id;
} public void setId(Long id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public int getBorn() {
return born;
} public void setBorn(int born) {
this.born = born;
}
}

添加Movie类

package org.mythsky.neo4jdemo;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship; import java.util.ArrayList;
import java.util.List; @JsonIdentityInfo(generator = JSOGGenerator.class)
@NodeEntity
public class Movie {
@GraphId
Long id;
String title;
String year;
String tagline;
@Relationship(type = "ACTS_IN",direction =Relationship.INCOMING)
List<Role> roles = new ArrayList<>(); public Long getId() {
return id;
} public void setId(Long id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getYear() {
return year;
} public void setYear(String year) {
this.year = year;
} public String getTagline() {
return tagline;
} public void setTagline(String tagline) {
this.tagline = tagline;
} public List<Role> getRoles() {
return roles;
} public void setRoles(List<Role> roles) {
this.roles = roles;
} public Movie() { } public Role addRole(Actor actor, String name){
Role role=new Role(name,actor,this);
this.roles.add(role);
return role; }
}

添加Role类

package org.mythsky.neo4jdemo;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import org.neo4j.ogm.annotation.EndNode;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.RelationshipEntity;
import org.neo4j.ogm.annotation.StartNode; @JsonIdentityInfo(generator = JSOGGenerator.class)
@RelationshipEntity(type = "ACTS_IN")
public class Role {
@GraphId
Long id;
String role;
@StartNode
Actor actor;
@EndNode
Movie movie; public Long getId() {
return id;
} public void setId(Long id) {
this.id = id;
} public String getRole() {
return role;
} public void setRole(String role) {
this.role = role;
} public Actor getActor() {
return actor;
} public void setActor(Actor actor) {
this.actor = actor;
} public Movie getMovie() {
return movie;
} public void setMovie(Movie movie) {
this.movie = movie;
} public Role(String role, Actor actor, Movie movie) { this.role = role;
this.actor = actor;
this.movie = movie;
} public Role() { }
}

添加查询接口MovieRepository

package org.mythsky.neo4jdemo;

import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; @Repository
public interface MovieRepository extends GraphRepository<Movie> {
Movie findByTitle(@Param("title") String title);
}

添加配置类

package org.mythsky.neo4jdemo;

import org.neo4j.ogm.session.SessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement; @Configuration
@EnableTransactionManagement
@EnableNeo4jRepositories public class Neo4jConfig {
@Bean
public SessionFactory sessionFactory() {
return new SessionFactory("org.mythsky.neo4jdemo");
} @Bean
public Neo4jTransactionManager transactionManager() {
return new Neo4jTransactionManager(sessionFactory());
}
}

添加配置文件ogm.properties

compiler=org.neo4j.ogm.compiler.MultiStatementCypherCompiler
driver=org.neo4j.ogm.drivers.http.driver.HttpDriver
URI=http://192.168.31.146:7474
username = neo4j
password = your own password

单元测试

package org.mythsky.neo4jdemo;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class)
@ContextConfiguration(classes = {Neo4jConfig.class})
@SpringBootTest
public class Neo4jDemoApplicationTests {
private static Logger logger= LoggerFactory.getLogger(Neo4jDemoApplicationTests.class);
@Autowired
MovieRepository movieRepository;
@Before
public void initData(){
movieRepository.deleteAll(); Movie matrix1=new Movie();
matrix1.setTitle("The Matrix");
matrix1.setYear("1999-03-31"); Movie matrix2=new Movie();
matrix2.setTitle("The Matrix Reloaded");
matrix2.setYear("2003-05-07"); Movie matrix3=new Movie();
matrix3.setTitle("The Matrix Revolutions");
matrix3.setYear("2003-10-27"); Actor keanu=new Actor();
keanu.setName("Keanu Reeves"); Actor laurence=new Actor();
laurence.setName("Laurence Fishburne"); Actor carrieanne=new Actor();
carrieanne.setName("Carrie-Anne Moss"); matrix1.addRole(keanu,"Neo");
matrix1.addRole(laurence,"Morpheus");
matrix1.addRole(carrieanne,"Trinity");
movieRepository.save(matrix1);
Assert.assertNotNull(matrix1.getId()); matrix2.addRole(keanu,"Neo");
matrix2.addRole(laurence,"Morpheus");
matrix2.addRole(carrieanne,"Trinity");
movieRepository.save(matrix2);
Assert.assertNotNull(matrix2.getId()); matrix3.addRole(keanu,"Neo");
matrix3.addRole(laurence,"Morpheus");
matrix3.addRole(carrieanne,"Trinity");
movieRepository.save(matrix3);
Assert.assertNotNull(matrix3.getId());
}
@Test
public void get() {
Movie movie=movieRepository.findByTitle("The Matrix");
Assert.assertNotNull(movie);
logger.info("===movie===movie:{},{}",movie.getTitle(),movie.getYear());
for(Role role:movie.getRoles()){
logger.info("=====actor:{},role:{}",role.getActor().getName(),role.getRole());
}
} }

运行测试

在浏览器查看数据

SpringBoot + docker + neo4j的更多相关文章

  1. windows环境 springboot+docker开发环境搭建与hello word

    1,下载安装 docker toolbox 下载地址:http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/ docker t ...

  2. SpringBoot Docker Mysql安装,Docker安装Mysql

    SpringBoot Docker Mysql安装,Docker安装Mysql ================================ ©Copyright 蕃薯耀 2018年4月8日 ht ...

  3. SpringBoot Docker入门,SpringBoot Docker安装

    SpringBoot Docker入门,SpringBoot Docker安装 ================================ ©Copyright 蕃薯耀 2018年4月8日 ht ...

  4. 【快学SpringBoot】SpringBoot+Docker构建、运行、部署应用

    前言 Docker技术发展为当前流行的微服务提供了更加便利的环境,使用SpringBoot+Docker部署和发布应用,其实也是一件比较简单的事情.当前,前提是得有Docker的基础. 源码在文末 文 ...

  5. springboot docker jenkins 自动化部署并上传镜像

    springboot + docker + jenkins自动化部署项目,jenkins.mysql.redis都是docker运行的,并且没有使用虚拟机,就在阿里云服务器(centos7)运行 1. ...

  6. 凭借SpringBoot整合Neo4j,我理清了《雷神》中错综复杂的人物关系

    原创:微信公众号 码农参上,欢迎分享,转载请保留出处. 哈喽大家好啊,我是Hydra. 虽然距离中秋放假还要熬过漫长的两天,不过也有个好消息,今天是<雷神4>上线Disney+流媒体的日子 ...

  7. 第三十七章 springboot+docker(手动部署)

    一.下载centos镜像 docker pull hub.c.163.com/library/centos:latest docker tag containId centos:7 docker ru ...

  8. Java开源博客My-Blog(SpringBoot+Docker)系列文章

    My Blog 1.Docker+SpringBoot+Mybatis+thymeleaf的Java博客系统开源啦 2.My-Blog搭建过程:如何让一个网站从零到可以上线访问 3.将数据的初始化放到 ...

  9. 【第三十七章】 springboot+docker(手动部署)

    一.下载centos镜像 docker pull hub.c.163.com/library/centos:latest docker tag containId centos:7 docker ru ...

随机推荐

  1. 在IIS7.5下配置PHP环境

    1.下载安装ZkeysPHP,路径随意 找到该程序集 D:\ZkeysSoft\Php\php5isapi.dll 2.在站点配置“处理程序映射”,添加php后缀映射由D:\ZkeysSoft\Php ...

  2. DataGuard 配置须知

    风不停,绿树荫,阳光晃眼,天真蓝,我们在奔跑,沿着斜阳,是你喘息,起伏不停...  ——朴树 1.确认primary库处于归档模式 命令:archive log list; 如果没有启用归档,请先将数 ...

  3. virtualbox centos 连接网络

    一.设置网络 设置 -> 网络 -> 连接方式:桥接网卡.设置当前连网络的界面名称.接入网线打勾 二.开启eth0 vi /etc/sysconfig/network-scripts/if ...

  4. centos6.4 安装wireless驱动

    安装完centos6.4之后,目测只有有线的驱动,没有无线驱动. 一.检测网卡 [root@centos ~]# lspci | grep Net :.11b/g LP-PHY (rev ) :) 第 ...

  5. noip第26课作业

    1.    信使 [问题描述] 战争时期,前线有n个哨所,每个哨所可能会与其他若干个哨所之间有通信联系.信使负责在哨所之间传递信息,当然,这是要花费一定时间的(以天为单位).指挥部设在第一个哨所.当指 ...

  6. jenkins+maven+svn构建项目,及远程部署war包到tomcat上

    要使用jenkins构建项目,当然要使用jenkins了,我使用的war版本的jenkins jenkins的官网 http://jenkins-ci.org/ 点击latest下载,但是可能因为天朝 ...

  7. pycharm的注册码,所有版本

    77751S0VBA-eyJsaWNlbnNlSWQiOiI3Nzc1MVMwVkJBIiwibGljZW5zZWVOYW1lIjoi5b285bK4IHNvZnR3YXJlMiIsImFzc2lnb ...

  8. springJDBC和SpringJDBCTemplate解决方案探究

    先来看一个纯JDBC的例子,体会一下springJDBC和SpringJDBCTemplate两者的区别 一个Customer类 package com.mkyong.customer.model; ...

  9. HDU2732一个让我debug了一晚上的题目

    思路都理解了,清晰了,就是代码不对,还是有些小地方自己注意不到,即使就在你的眼前也不易发现的那种 Description: 也是一个最大流的构图,没相出来,或者说想简单了也是标记点1 至 n * m是 ...

  10. poj2186tarjan算法缩点求出度

    poj2186tarjan算法缩点求出度 自己打一遍第一题,入门啦,入门啦 题目还算简单,多头牛,给你仰慕关系(可传递),问你最后有没有牛被所有的牛仰慕 根据关系可以建图,利用tarjan算法缩点处理 ...