[스프링 부트] chapter 35. 스프링 데이터 11부 Neo4j
스프링 데이터 11부 Neo4j
Neo4j는 노드간의 연관 관계를 영속화하는데 유리한 그래프 데이터베이스
의존성 추가
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
Neo4j 설치 및 실행 (도커)
-
docker run -p 7474:7474 -p 7687:7687 –name neo4j_boot -d neo4j
-
http://localhost:7575/browser
-
neo4j를 스프링 부트에서 사용하기 위해서는 application.properties에 설정해야 함
spring.data.neo4j.username=neo4j spring.data.neo4j.password= # 최초 접속했을 때 비번은 neo4j, 접속 후 변경해야 함. 위에는 변경된 비밀번호 작성
예제
@Component
public class Neo4jRunner implements ApplicationRunner {
@Autowired
SessionFactory sessionFactory;
@Override
public void run(ApplicationArguments args) throws Exception {
Account account = new Account();
account.setEmail("juho@mail.com");
account.setUsername("juho");
Session session = sessionFactory.openSession();
session.save(session);
sessionFactory.close();
}
}
스프링 데이터 Neo4j
- Neo4jTempalte (Deprecated)
- SessionFactory
- Neo4jRepository