2

Spring Data Neo4j を使用して webapp を作成しようとしています。

私はリポジトリを持っています:

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;
    ...

nullであるため、コントローラーでUserRepositoryを使用できません...

間違いはどこですか?

4

2 に答える 2

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();

これが役立つことを願っています...

于 2012-11-14T21:51:38.687 に答える
0

@Autowiredstaticフィールドでは機能しません。

また、設計の観点から、このフィールドを作成することはお勧めできませんstatic

于 2012-07-26T09:27:12.067 に答える