gpt4 book ai didi

java - Neo4j 与 Spring : No bean named 'getSessionFactory' available

转载 作者:太空宇宙 更新时间:2023-11-04 11:12:44 26 4
gpt4 key购买 nike

我对 Neo4j 和 Spring 的组合以及 Spring 都是新手。当我开始调试时,出现以下异常:

Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'getSessionFactory' available

有人可以帮我吗?

应用上下文.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/neo4j
http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

<context:component-scan base-package="de.unileipzig.analyzewikipedia.neo4j" />

<!--neo4j:config storeDirectory="C:/temp/neo4jdatabase" base-package="de.unileipzig.analyzewikipedia.neo4j.dataobjects"/-->

<neo4j:repositories base-package="de.unileipzig.analyzewikipedia.neo4j.repositories"/>

<tx:annotation-driven />

<bean id="graphDatabaseService" class="org.springframework.data.neo4j.support.GraphDatabaseServiceFactoryBean"
destroy-method="shutdown" scope="singleton">
<constructor-arg value="C:/develop/uni/analyze-wikipedia-netbeans/database"/>
<constructor-arg>
<map>
<entry key="allow_store_upgrade" value="true"/>
</map>
</constructor-arg>
</bean>
</beans>

启动类

软件包 de.unileipzig.analyzewikipedia.neo4j.console;

import de.unileipzig.analyzewikipedia.neo4j.dataobjects.Article;
import de.unileipzig.analyzewikipedia.neo4j.service.ArticleService;
import java.io.File;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Neo4JConsole {
/**
* MAIN: start the java file
*
* @param args as string array
*/
public static void main(String[] args) {

String cwd = (new File(".")).getAbsolutePath();
ApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
ArticleService service = (ArticleService) context.getBean("articleService");

Article art = createArticle();
createArticle(service, art);

System.out.println("Article created");
}

private static Article createArticle() {
Article article = new Article();
article.setTitle("Title");
return article;
}

private static Article createArticle(ArticleService service, Article art) {
return service.create(art);
}
}

谢谢。

最佳答案

你有这个配置吗?

@Configuration
@EnableNeo4jRepositories("org.neo4j.cineasts.repository")
@EnableTransactionManagement
@ComponentScan("org.neo4j.cineasts")
public class PersistenceContext extends Neo4jConfiguration {

@Override
public SessionFactory getSessionFactory() {
return new SessionFactory("org.neo4j.cineasts.domain");
}
}

有关更多信息,请尝试查看 here

关于java - Neo4j 与 Spring : No bean named 'getSessionFactory' available,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45814676/

26 4 0