尝试在2个类中使用我的AccountService(@Service)来解决这个错误:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mz.springContextWorld.repositories.AccountRepository com.mz.springContextWorld.services.AccountService.accountRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountRepository': Cannot resolve reference to bean 'neo4jTemplate' while setting bean property 'neo4jTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.neo4j.config.Neo4jConfiguration#0': Cannot resolve reference to bean 'graphDatabaseService' while setting bean property 'graphDatabaseService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphDatabaseService': FactoryBean threw exception on object creation; nested exception is java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, /home/matthias/IdeaProjects/springContextWorld/target/neo4j-db-plain
这是我的github回购:https://github.com/mzober/springContextWorld/tree/CollectorManager_ErrorBranch
以下是我的accountService的使用:
@Autowired
AccountService accountService;
public LoginPanel() {
//errorline here
this.accountService=GuiFactory.getInstance().mainWindow().getAccountService();
init();
addComponents();
}
...
@Autowired
AccountService accountService;
public RegistryAndLoginListener() {
//no error here
accountService=GuiFactory.getInstance().mainWindow().getAccountService();
}
...从context-configuration获取accountService:
<context:annotation-config/>
<context:spring-configured/>
<context:component-scan base-package="com.mz.springContextWorld.domain"/>
<context:component-scan base-package="com.mz.springContextWorld.repositories"/>
<context:component-scan base-package="com.mz.springContextWorld.gui.listener"/>
<context:component-scan base-package="com.mz.springContextWorld.gui.components"/>
<context:component-scan base-package="com.mz.springContextWorld.gui.creational"/>
<context:component-scan base-package="com.mz.springContextWorld.services"/>
<neo4j:config storeDirectory="target/neo4j-db-plain"
base-package="com.mz.springContextWorld.domain"/>
<neo4j:repositories base-package="com.mz.springContextWorld.repositories"/>
<tx:annotation-driven />
...在MainWindow中加载配置(我的Spring-Data-Neo4j的演示应用程序)
@Autowired
public AccountService accountService;
public MainWindow() {
super(PROJECTNAME);
context= new ClassPathXmlApplicationContext("spring/spring-config.xml");
accountService=(AccountService)context.getBean("accountService");
...
}
public AccountService getAccountService(){return this.accountService;}
AccountService:
@Service
@Transactional
public class AccountService {
@Autowired
AccountRepository accountRepository;
public AccountService(){
}
@Transactional
public Iterable<Account> getAll() {
return accountRepository.findAll();
}...
这是我的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mz.springContextWorld</groupId>
<artifactId>springContextWorld</artifactId>
<packaging>jar</packaging>
<version>3.2.1.RELEASE</version>
<name>springContextWorld</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.0.7.RELEASE</spring.version>
<spring-data-neo4j.version>${project.version}</spring-data-neo4j.version>
<slf4j.version>1.7.5</slf4j.version>
<neo4j.version>2.1.5</neo4j.version>
<junit.version>4.11</junit.version>
</properties>
<repositories>
<repository>
<id>neo4j-release-repository</id>
<name>Neo4j Maven 2 release repository</name>
<url>http://m2.neo4j.org/releases</url>
</repository>
</repositories>
<dependencies>
<!--spring data-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>${spring-data-neo4j.version}</version>
</dependency>
<!--spring data end-->
<!--hibernate-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.1.Final</version>
</dependency>
<!--hibernate end-->
<!--test-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>${neo4j.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<!--test end-->
<!--Loading Related dependencies ...logging-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!--logging end-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
...我试图将txmode设置为代理,但错误仍然存在...
帮助
答案 0 :(得分:0)
好像你的neo4j数据库无法启动。检查上一个日志行:Error starting org.neo4j.kernel.EmbeddedGraphDatabase, /home/matthias/IdeaProjects/springContextWorld/target/neo4j-db-plain