Spring数据neo4j:当结果传递给另一个列表时,findAll返回null

时间:2015-01-29 08:50:03

标签: java spring neo4j spring-data-neo4j

问题是:我有Spring数据neo4j jar,它有Spring服务,我得到结果列表,但后来我把结果传递到前端它是null。 创建数据,后端结果不为空。

 @Autowired
    private Neo4jTemplate template;
    @Autowired
    private ArticleRepository articleRepository;
    @Autowired
    private GraphDatabaseService graphDatabaseService;
    @Autowired
    private Neo4jOperations neo4jOperations;


    @Transactional
    public List<Article> getAllArticleList() {
        List<Article> allList = new ArrayList<Article>();
        Iterable<Article> items = template.findAll(Article.class);
        if (items != null) {
            for (Article u : items) {
                // Article item = neo4jOperations.convert(u, Article.class);
                System.out.println("Article " + u.getId());
                System.out.println("Article 2 " + u.getArticleName());
                allList.add(u);
            }
        }
        return allList;
    }

这里打印结果,打印后我将它添加到allList。

第二部分,

这是一个来自JSF bean的方法,形成这个bean也是我做的测试数据, size是打印,但数据为空。

public List<Article> getAllArticles() {
        List<Article> allList = new ArrayList<Article>();
         System.out.println("##########Article list size######### " + cognitiveService.getAllArticleList().size());
           for (Article cc : springBean.getAllArticleList()) {
                System.out.println("Article id is::@@ " + cc.getId());
                System.out.println("Article name:::@@ " + cc.getArticleName());
            }
           try {             
            allList.addAll(springBean.getAllArticleList());            

            for (Article c : allList) {
                System.out.println("Article id is:: " + c.getId());
                System.out.println("Article name::: " + c.getArticleName());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return allList;
    }

Spring neo4j配置

@Configuration
@ComponentScan(basePackages = {"com"}, excludeFilters = {
    @ComponentScan.Filter(Configuration.class)})
@ImportResource("classpath:META-INF/spring/application-context.xml")
@EnableTransactionManagement(mode = AdviceMode.PROXY)
@EnableScheduling
@EnableAsync
//@EnableTransactionManagement
@EnableMBeanExport
@EnableWebMvc
@EnableNeo4jRepositories(basePackages = "com")
public class Application extends Neo4jConfiguration {

    public Application() {
        setBasePackage("com");
    }  

    @Bean
    public GraphDatabaseService graphDatabaseService() {
        return new GraphDatabaseFactory().newEmbeddedDatabase("C:/neo4j/db/testdata.db");
    }

XML

<context:annotation-config/>
    <context:spring-configured/>

    <neo4j:config id="graphDatabaseService" storeDirectory="C:/neo4j/db/testdata.db"  base-package="com.neo4jia.domain"/>
<!--                  -->


    <!-- Instructs Spring Data where to look for repository implementations -->
    <neo4j:repositories base-package="com.neo4jia.repository"/>

<!--     We override the default Label based Type Representation strategy by supplying
    our own "typeRepresentationStrategyFactory" which uses the Legacy indexed based
    strategy. From SDN 3.0 onwards, the default type representation strategy
    is Label based, and in 2.3 and previous it was Indexed based. 
    <bean id="typeRepresentationStrategyFactory" class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory">
        <constructor-arg index="0" ref="graphDatabase"/>
        <constructor-arg index="1" value="Indexed"/>
    </bean>-->

    <tx:annotation-driven mode="aspectj"/>

我尝试将表格列表更改为Iterable .....结果相同,数据未通过。

  <neo4j.version>2.1.5</neo4j.version>
        <neo4j.springdata.version>3.2.1.RELEASE</neo4j.springdata.version>
 <spring.version>4.0.7.RELEASE</spring.version>

1 个答案:

答案 0 :(得分:0)

来自存储库命名的所有问题。

我将存储库名称更改为UserRelationRepository,将Spring服务名称更改为 UserRelationService。 以前我做过类似的事情,这次我更改了存储库名称:((

它解决了旧版本的Spring数据neo4j,但新的仍然存在。 我正在与配置的项目共享一个链接,任何人都可以下载并运行并找到问题所在?这是tomcat7 / 8下的maven项目工作,您可以从网页单击查看创建的节点,但无法获取节点名称。

链接download the project