【问题标题】:Spring Data Neo4J and CDISpring Data Neo4J 和 CDI
【发布时间】:2015-02-02 12:19:56
【问题描述】:
【问题讨论】:
标签:
spring
neo4j
spring-data
cdi
【解决方案1】:
至少我发现了一些似乎有效的东西。我扩展了 Neo4JConfiguration 来设置 Neo4J 服务器连接。在这个类中,我还生成了所需的存储库。存储库本身必须使用 @NoRepositoryBean 注释
public class MyNeo4JConfiguration extends Neo4jConfiguration {
GraphDatabaseService graphDatabaseService() {
return new SpringRestGraphDatabase("http://localhost:7474/db/data");
}
public GraphDatabase graphDatabase() {
if (graphDatabaseService() instanceof GraphDatabase)
return (GraphDatabase) graphDatabaseService();
return new DelegatingGraphDatabase(graphDatabaseService());
}
@Produces
PersonRepository getPersonRepository() {
GraphRepositoryFactory factory;
try {
factory = new GraphRepositoryFactory(new Neo4jTemplate(
this.graphDatabase()), this.neo4jMappingContext());
PersonRepository personRepository = factory
.getRepository(PersonRepository.class);
return personRepository;
} catch (Exception e) {
return null;
}
}
存储库:
@NoRepositoryBean
public interface PersonRepository extends GraphRepository<Person> {
Person findByName(String name);
Iterable<Person> findByTeammatesName(String name);
}
现在可以使用@Inject 注入 PersonRepository。
感谢this 发帖!!!