2012-07-26 3 views
2

스프링 데이터 Neo4j를 사용하여 웹 애플리케이션을 작성하려고합니다.스프링 데이터 Neo4j - @Autowired Repository == null

나는 저장소가 있습니다

public interface UserRepository extends GraphRepository<Neo4jUser> {} 

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 :

지금
@Controller 
public class Neo4jResource { 

    @Autowired 
    public static UserRepository repo; 
    ... 

가있는 UserRepository을 사용할 수 없습니다 컨트롤러가 널이기 때문에 ...

어디서 실수입니까?

답변

0

@Autowiredstatic 필드에 대해 작동하지 않습니다.

또한이 필드를 디자인 관점에서보기에는 좋지 않습니다. static.

+0

죄송하지만 여전히 "널 (null)"... – Tschakle

0

내가 생각할 수있는 몇 가지 :

  1. 귀하의 <neo4j:repositories base-package=".."/> is not correct
  2. 당신은 제대로 applicationContext로드되지 않으며 repo 먼저 패키지를 확인 제대로

을 인스턴스화되지 않습니다 . 또한 주 응용 프로그램에 다음과 같은 항목이 있습니까? 희망이 도움이 것을

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

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

...

관련 문제