Spring数据neo4j没有这样的方法错误

时间:2016-04-08 07:20:24

标签: java spring neo4j spring-data

我正在关注Spring's tutorial并在尝试为用户模型运行简单的CRUD时遇到此错误:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.app.adhoc.neo4j.repository.UserRepository com.app.adhoc.controller.Neo4JExportController.userRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.data.neo4j.repository.support.GraphRepositoryFactoryBean.setMappingContext(Lorg/springframework/data/mapping/context/MappingContext;)V
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 15 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.data.neo4j.repository.support.GraphRepositoryFactoryBean.setMappingContext(Lorg/springframework/data/mapping/context/MappingContext;)V
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1572)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
    ... 17 more
Caused by: java.lang.NoSuchMethodError: org.springframework.data.neo4j.repository.support.GraphRepositoryFactoryBean.setMappingContext(Lorg/springframework/data/mapping/context/MappingContext;)V
    at org.springframework.data.neo4j.repository.support.GraphRepositoryFactoryBean.afterPropertiesSet(GraphRepositoryFactoryBean.java:42)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
    ... 27 more

这是我的用户存储库界面:

@Repository
public interface UserRepository extends GraphRepository<UserModel> {
  public List<UserModel> findById(String id);
  public List<UserModel> findByName(String name);

  @Query("MATCH (n) WHERE id(n)={0} RETURN n")
  UserModel getUserFromId(Integer userId);

  @Query("MATCH (usr:User {title={0}}) RETURN usr")
  UserModel getUserFromTitle(String userName);

  @Query("MATCH (usr:User {title:{title}})<-[r:RATED]-(user) " +
         "WHERE r.stars > {rating} " +
         "RETURN user")
   Iterable<UserModel> getUsersWhoRated(@Param("title") String movieTitle,
                                                 @Param("rating") Integer rating);  
}

这是我的配置:

@Configuration
@EnableTransactionManagement
@EnableNeo4jRepositories("com.app.adhoc.neo4j.repository")
@ComponentScan(basePackages = {"com.app.adhoc"})
public class Neo4JConfig extends Neo4jConfiguration{

  private static final Logger LOGGER = LoggerFactory.getLogger(Neo4JConfig.class);

  @Value("${neo4j.server.user}")
  private static final String neoUser = "";

  @Value("${neo4j.server.pass}")
  private static final String neoPass = "";

  @Value("${neo4j.server.host}")
  private static final String neoHost = "";

  @Resource
  private Environment environment;

  @Bean
  public Neo4jServer neo4jServer(){
    LOGGER.info("Connecting to remote server...");
    return new RemoteServer(neoHost, neoUser, neoPass);
  }

  @Bean
  public SessionFactory getSessionFactory(){
    LOGGER.info("Getting session factory...");
    return new SessionFactory("com.app.adhoc.neo4j.domain");
  }

  @Bean
  @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
  public Session getSession() throws Exception{
    return super.getSession();
  }

问题:

错误来自自动装配存储库,而我还没有对存储库执行任何其他操作。我想知道出了什么问题。

编辑:

添加了我的neo4j相关pom.xml

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-commons-core</artifactId>
    <version>1.4.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j</artifactId>
    <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-commons</artifactId>
    <version>1.12.1.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j-rest</artifactId>
    <version>3.4.4.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.neo4j.app</groupId>
    <artifactId>neo4j-server</artifactId>
    <version>2.3.1</version>
</dependency>


<dependency>
    <groupId> javax.transaction </groupId>
    <artifactId> jta </artifactId>
    <version> 1.1 </version>
</dependency>

<dependency>
    <groupId> org.neo4j </groupId>
    <artifactId> neo4j-kernel </artifactId>
    <version> 2.1.3 </version>
</dependency>

0 个答案:

没有答案