How to configure the Neo4j repository with Spring Data Neo4j 3.4.0?

梦想与她 提交于 2019-12-11 10:43:20

问题


I tried to upgrade from the 3.3.2 to the 3.4.0 version of spring data neo4j on search.maven.org but the build now gives the following exception:

AnnotationFormatError: Invalid default: public abstract java.lang.Class org.springframework.data.neo4j.config.EnableNeo4jRepositories.repositoryBaseClass()

The application works just fine in 3.3.2.

Here is the configuration class:

@Configuration
@EnableNeo4jRepositories(basePackages = { "it.data.neo4j.repository" })
@EnableTransactionManagement
@ComponentScan(basePackages = { "it.data.neo4j.service" })
public class Neo4JRepositoryConfiguration extends Neo4jConfiguration {

  private static Logger logger = LoggerFactory.getLogger(Neo4JRepositoryConfiguration.class);

  public static final String URL = "http://localhost:7474/db/data/";
  public static final String LOGIN = "neo4j";
  public static final String PASSWORD = "xxxx";

  Neo4JRepositoryConfiguration() {
    setBasePackage("it.data.neo4j.domain");
  }

  @Bean
  GraphDatabaseService graphDatabaseService() {
    return new SpringCypherRestGraphDatabase(URL, LOGIN, PASSWORD);
  }

  @Autowired
  LocalContainerEntityManagerFactoryBean entityManagerFactory;

  @Override
  public PlatformTransactionManager neo4jTransactionManager(
      GraphDatabaseService graphDatabaseService) {
    return new ChainedTransactionManager(
        new JpaTransactionManager(entityManagerFactory.getObject()),
        new JtaTransactionManagerFactoryBean(graphDatabaseService).getObject());
  }

}

The dependencies are:

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

回答1:


Most likely a conflicting class path dependencies with spring-data-commons.jar

Make sure all jars on the class path are using the same version of spring-data-commons.

In my case I had 2 jars referencing both spring-data-commons.jar 1.10 and 1.11 which caused the issue.




回答2:


Does your package it.data.neo4j.repository contain both JPA and Neo4j repositories? If so you may need to segregate them into separate packages.

Additionally, Spring Data Neo4j version 4 is a major shift from the previous versions and a bit of code migration is involved, it is possible your actual application code needs to be adjusted to be compatible with SDN4:

http://docs.spring.io/spring-data/neo4j/docs/4.0.0.RELEASE/reference/html/#migration



来源:https://stackoverflow.com/questions/32505105/how-to-configure-the-neo4j-repository-with-spring-data-neo4j-3-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!