【发布时间】:2014-09-09 02:54:11
【问题描述】:
我正在尝试在独立应用程序中使用 Spring Data Neo4j 编写“Hello, World”。它运行并实际创建了 Neo4j 数据库,但我的 @Autowired 存储库没有被初始化。我怀疑问题出在我的主课上,但我不知道该尝试什么。不出所料,我发现的几乎所有 Spring 教程都是关于 Web 应用程序的。
我做错了什么?
配置 bean:
@Configuration
@EnableNeo4jRepositories(basePackages = "test2")
public class ConfigBean extends Neo4jConfiguration {
private static final String DB_PATH = "/home/kevin/tmp/hello-spring-data-neo4j/";
public ConfigBean() {
setBasePackage("test2");
}
@Bean
public GraphDatabaseService graphDatabaseService() {
return new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
}
}
节点实体:
@NodeEntity
public class Foo {
@GraphId
private Long id;
}
存储库:
public interface FooRepository extends GraphRepository<Foo> { }
主类:
@Component
public class Test2 {
@Autowired
FooRepository repo;
public void doStuff() {
System.out.println("repo: " + repo); // null!
}
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext("test2");
new Test2().doStuff();
}
}
它记录了大约 350 行输出。这是最后几行。我搜索了这个错误信息,但我得到的印象是它与我的问题无关。
20:44:30.630 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemProperties]
20:44:30.631 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
20:44:30.635 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [null]
repo: null
【问题讨论】:
标签: neo4j spring-data spring-data-neo4j