春季数据的Neo4j - @Autowired仓库== NULL [英] Spring Data Neo4j - @Autowired Repository == null

查看:247
本文介绍了春季数据的Neo4j - @Autowired仓库== NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试写使用Spring数据Neo4j的web应用程序。

I try to write a webapp using Spring Data Neo4j.

我有一个存储库:

public interface UserRepository extends GraphRepository<Neo4jUser> {} 

这是applicationContext.xml的:

an applicationcontext.xml:

...
<context:component-scan base-package="de.wilke.test.neo4j" >
    <context:exclude-filter type="annotation" 
          expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

<!-- REST Connection to Neo4j server --> 
<bean id="restGraphDatabase" 
    class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
    <constructor-arg value="http://localhost:7474/db/data/" />
</bean>

<bean id="myservice" class="de.wilke.test.neo4j.Neo4jResource">
</bean>

<!-- Neo4j configuration (template) -->
<neo4j:config graphDatabaseService="restGraphDatabase" />

<!-- Package w/ automagic repositories -->
<neo4j:repositories base-package="de.wilke.test.repository" /> 

和我Neo4jResource:

And my Neo4jResource:

@Controller
public class Neo4jResource {

    @Autowired
    public static UserRepository repo;
    ...

现在不能使用UserRepository的控制器,因为它是空...

Now cannot use the UserRepository in the Controller because it is null...

在哪儿错了吗?

推荐答案

一对夫妇的事情,我能想到的:

A couple of things that I can think of:


  1. &LT; Neo4j的:仓库基础包=/&GT;不正确

  2. 您不加载你的的applicationContext 正确和回购没有得到正确的实例

  1. Your <neo4j:repositories base-package=".."/> is not correct
  2. You are not loading your applicationContext correctly and the repo does not get instantiated properly

首先检查你的包。此外,你有一个像在主应用程序下面的东西吗?

Check your package first. Also, do you have anything like the following in your main application?

ConfigurableApplicationContext context;
context = new ClassPathXmlApplicationContext("spring/applicationContext.xml");

Neo4jResource myBean = context.getBean(Neo4jResource.class);
myBean.functionThatUsesTheRepo();

希望这有助于...

Hope that this helps...

这篇关于春季数据的Neo4j - @Autowired仓库== NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆