心态炸了,我再写一个4.1.0版本的SND实例

maven依赖



org.springframework
spring-test
4.2.5.RELEASE
test




org.springframework.data
spring-data-neo4j
4.1.0.RELEASE




org.neo4j
neo4j-ogm-test
2.1.0
test



org.neo4j
neo4j-kernel
3.1.0



org.neo4j.app
neo4j-server
3.1.0



org.neo4j.test
neo4j-harness
3.1.0
test



junit
junit
4.12
test

domain model(com.shubo.neo4j.domain)

@NodeEntity
public class Person {
@GraphId
private Long nodeId;
String name;
String from;
String hobbies;

public Person(){
}

public Person(String name,String from, String hobbies){
this.name = name;
this.from = from;
this.hobbies = hobbies;
}

}

repository(com.shubo.neo4j.repositories)

public interface PersonRepository extends GraphRepository {
}

configuration(ogm.repositories,SDN会自动扫描该文件,以及配置方法的声明和一个使用实例)

@Configuration
@EnableNeo4jRepositories(basePackages = "com.shubo.neo4j.repository")
@EnableTransactionManagement
@ComponentScan("com.shubo.neo4j")
public class MyConfiguration extends Neo4jConfiguration{
@Bean
public SessionFactory getSessionFactory(){
return new SessionFactory("com.shubo.neo4j.domain");
}

@Bean
public Session getSession() throws Exception {
return super.getSession();
}
}

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {MyConfiguration.class})
public class Neo4jTest {

@Autowired
PersonRepository personRepository;

@Test
public void testCRUDPerson(){
System.out.println(personRepository.getClass());
Person person = new Person("Jerry","China","LOL");
personRepository.save(person);
System.out.println("保存成功");
}
}


转载于:https://www.cnblogs.com/shirandedan/p/7199459.html


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部