SpringBoot + docker + neo4j
下拉镜像
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的更多相关文章
- windows环境 springboot+docker开发环境搭建与hello word
1,下载安装 docker toolbox 下载地址:http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/ docker t ...
- SpringBoot Docker Mysql安装,Docker安装Mysql
SpringBoot Docker Mysql安装,Docker安装Mysql ================================ ©Copyright 蕃薯耀 2018年4月8日 ht ...
- SpringBoot Docker入门,SpringBoot Docker安装
SpringBoot Docker入门,SpringBoot Docker安装 ================================ ©Copyright 蕃薯耀 2018年4月8日 ht ...
- 【快学SpringBoot】SpringBoot+Docker构建、运行、部署应用
前言 Docker技术发展为当前流行的微服务提供了更加便利的环境,使用SpringBoot+Docker部署和发布应用,其实也是一件比较简单的事情.当前,前提是得有Docker的基础. 源码在文末 文 ...
- springboot docker jenkins 自动化部署并上传镜像
springboot + docker + jenkins自动化部署项目,jenkins.mysql.redis都是docker运行的,并且没有使用虚拟机,就在阿里云服务器(centos7)运行 1. ...
- 凭借SpringBoot整合Neo4j,我理清了《雷神》中错综复杂的人物关系
原创:微信公众号 码农参上,欢迎分享,转载请保留出处. 哈喽大家好啊,我是Hydra. 虽然距离中秋放假还要熬过漫长的两天,不过也有个好消息,今天是<雷神4>上线Disney+流媒体的日子 ...
- 第三十七章 springboot+docker(手动部署)
一.下载centos镜像 docker pull hub.c.163.com/library/centos:latest docker tag containId centos:7 docker ru ...
- Java开源博客My-Blog(SpringBoot+Docker)系列文章
My Blog 1.Docker+SpringBoot+Mybatis+thymeleaf的Java博客系统开源啦 2.My-Blog搭建过程:如何让一个网站从零到可以上线访问 3.将数据的初始化放到 ...
- 【第三十七章】 springboot+docker(手动部署)
一.下载centos镜像 docker pull hub.c.163.com/library/centos:latest docker tag containId centos:7 docker ru ...
随机推荐
- shell常用符号的意义
转自:http://blog.sina.com.cn/mo0928 感谢原作者!!! 跟網路農夫了解UNIX SHELL-(Bash scripting 简介 第四章 特殊符号) (2007-08-1 ...
- laravel 5.1 使用Eloquent ORM 操作实例
Laravel 的 Eloquent ORM 提供了更优雅的ActiveRecord 实现来和数据库的互动. 每个数据库表对应一个模型文件. 数据库配置 .env文件(也可以直接修改config/da ...
- [待完善]mycat分布式架构部署
mycat介绍:http://mycat.org.cn/ mycat分布式架构部署
- (转载)Fiddler实战深入研究(二)
原文来源于:http://www.cnblogs.com/tugenhua0707/p/4637771.html,作者:涂根华 !个人觉得文章写的特别好,故收藏于此,感谢原作者的分享 Fiddler实 ...
- 安装mysql后必做的两件事
1..删除掉不需要的用户 查看用户表mysql> SELECT User,Host FROM mysql.user; +------+-------------------------+ | U ...
- stm32f103_高级定时器——输入捕获/输出比较中断+pwm=spwm生成
****************************首选我们了解一下它们的功能吧********************************************************** ...
- mantis邮件设置
1.cd /var/www/html/mantis 删除 config_inc.php 的$g_enable_email_notification = OFF; 重启httpd ...
- Python自动化开发 -进程、线程和协程(二)
本节内容 一.线程进程介绍 二. 线程 1.线程基本使用 (Threading) 2.线程锁(Lock.RLock) 3.信号量(Semaphore) 4.事件(event) 5.条件(Conditi ...
- Winform DataGridView控件在业务逻辑上的简单使用
需要对文字列表进行处理,然后用到DataGridView控件来处理,记录一下.效果如下: 主要是想通过禁用和取消单元格选择来使图标单元格呈现出鼠标点击的效果.因为有个单元格选择的问题困扰着我. 是这样 ...
- WPF学习笔记(2):准确定位弹出窗
效果图:使弹出的列表框紧随在单元格的下边缘. 第一次,尝试在XAML中设置Popup的定位方式:Placement="Mouse".基本能够定位,但当在输入前移动鼠标,列表框就会随 ...