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 ...
随机推荐
- 二级缓存EhCache在几种应用技术的配置方法和步骤总结
一:Spring和Ehcache缓存集成 业务问题:如果仓库不经常变动,大量进出库,总是需要查询仓库列表 (列表重复) ,使用缓存优化 ! 阅读spring规范29章节 第一步: 导入ehcache的 ...
- wifi adb 的常用命令
Android 网络调试 adb tcpip 开启方法 2013年05月14日 10:01:03 阅读数:20529 1.连接USB数据线,打开usb调试,使用windows的“运行”命令行方式:(此 ...
- 12-简单认识下margin
margin margin:外边距的意思.表示边框到最近盒子的距离. /*表示四个方向的外边距离为20px*/ margin: 20px; /*表示盒子向下移动了30px*/ margin-top: ...
- Page页面生命周期——微信小程序
onLoad:function (options) { //页面初始化 console.log('index Load') }, onShow:function () { // ...
- day31(正则表达式)
1.校验密码强度密码的强度必须是包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间.^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$ 2. 校验中文字符串 ...
- 待了解概念_GraphicsView
Linux 的 KDE 是建立在 Graphics view基础上的. 新版本KDE 有向QML前移的趋势. Graphics View 使用了BSP 树的结构. Graphics View 是一个基 ...
- Java相关工具下载、配置环境变量
相关工具下载 JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html Eclip ...
- VS中的调试相关的技巧
1. 可以设置断点的命中条件:
- poj 2531 搜索剪枝
Network Saboteur Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u ...
- kafka各个版本特点介绍和总结
kafka各个版本特点介绍和总结 1.1 kafka的功能特点: 分布式消息队列 消息队列的数据模型, 形成流式数据. 提供Pub/Sub方式的海量消息处理.以高容错的方式存储海量数据流.保证数据流的 ...