3

I'm migrating from spring-data-neo4j version 4.1 to 4.2. On the application startup I'm getting an error: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.neo4j.ogm.session.Session' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

repository.ActivityRecordRepository.java:

public interface ActivityRecordRepository extends GraphRepository<ActivityRecord>, ActivityRecordRepositoryCustom {}

repository.ActivityRecordRepositoryCustom.java:

public interface ActivityRecordRepositoryCustom {
   ...
}

repository.impl.ActivityRecordRepositoryImpl.java:

public class ActivityRecordRepositoryImpl implements ActivityRecordRepositoryCustom {

    private final Session session;

    public ActivityRecordRepositoryImpl(Session session) {
        this.session = session;
    }

    ....
}

My configuration:

@ComponentScan
@Configuration
@EnableNeo4jRepositories("com.example.repository")
@EnableTransactionManagement
public class ApplicationConfiguration {

    ....        

    @Bean
    public EventListener eventListener() {
        return new CustomEventListener();
    }

    @Bean
    public SessionFactory getSessionFactory() {       
        final SessionFactory sessionFactory = new SessionFactory(databaseConfiguration, "com.example.entity");
        sessionFactory.register(eventListener());
        return sessionFactory;
    }
}

How to properly autowire session object to custom repository implementation?

I'm using: Spring Version: 4.3.2.RELEASE
Spring Data Neo4j Version: 4.2.11.RELEASE

Slava
  • 311
  • 3
  • 9
  • 1
    Does it work for you to autowire the `SessionFactory` instead of a `Session`? – meistermeier Apr 19 '18 at 10:46
  • 1
    @meistermeier no then it fails with this exception: ```Factory method 'getSessionFactory' threw exception; nested exception is java.lang.NoSuchMethodError: org.neo4j.ogm.session.SessionFactory.register(Lorg/neo4j/ogm/session/event/EventListener;)``` – Slava Apr 19 '18 at 13:05
  • @Slava Sorry for my 5 cents but I'm just wondering why do you need to migrate to SDN4.2 when SDN 5.x already exists? – alexanoid Apr 23 '18 at 10:27
  • @alexanoid because sdn 5.x requires spring version 5+. My project using spring 4 – Slava Apr 24 '18 at 20:23
  • https://neo4j.com/blog/spring-data-neo4j-4-1-applications/ I think it's an example that conforms to Neo4J and Spring versions that you're looking for. – garfield May 01 '18 at 07:02
  • @alexanoid With SDN 5.x does not work either https://stackoverflow.com/questions/50356497/spring-data-neo4j-5-no-bean-named-sessionfactory-available – Slava May 16 '18 at 10:08

0 Answers0