2

I have a console module / app (not a webapp), which I'd like to use with a service module / app built using spring-data-neo4j.

Console App ---> Uses Spring Data Neo4j module

I'm using what I think is the standard way to configure my session, session factory and server (code pasted below), inheriting from Neo4jConfiguration.

When the console app tries to use the ogm session in the spring-data-neo4j service module, I get the error message:

Caused by: java.lang.IllegalStateException: No Scope registered for scope 'session'
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:336)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
        at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:187)
        at com.sun.proxy.$Proxy51.loadAll(Unknown Source)
        at nz.co.thescene.core.member.MemberAccountService.loadMemberByEmailAddressPasswordAccount(MemberAccountService.java:95)
        at nz.co.thescene.console.menu.Menu.login(Menu.java:36)
        at nz.co.thescene.console.menu.Menu.login(Menu.java:98)
        at nz.co.thescene.console.menu.MainMenu.processUserInput(MainMenu.java:107)
        at nz.co.thescene.console.menu.Menu.processUserInput(Menu.java:82)
        at nz.co.thescene.console.ConsoleUI.run(ConsoleUI.java:64)
        at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:672)
        ... 9 more

My config is below:

@Configuration
@ComponentScan("nz.co.*****")
@EnableTransactionManagement
@EnableNeo4jRepositories(basePackages = "nz.co.*****")
@EnableConfigurationProperties(Neo4jProperties.class)
public class Neo4jConfig extends Neo4jConfiguration {

    private static final Logger log = LoggerFactory.getLogger(Neo4jConfig.class);

    @Inject
    private Neo4jProperties properties;

    @PostConstruct
    public void init() {
        log.debug("Initializing Neo4jConfig...");
    }

    @Bean
    @Override
    public Neo4jServer neo4jServer() {
        log.info("Initialising server connection");
        return new RemoteServer(properties.getUrl(), properties.getUsername(), properties.getPassword());
        //return new InProcessServer();
    }

    @Bean
    @Override
    public SessionFactory getSessionFactory() {
        log.info("Initialising Session Factory");
        return new SessionFactory("nz.co.*****");
    }

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

}

What do I need to do to get this to work?

John Deverall
  • 5,954
  • 3
  • 27
  • 37

1 Answers1

1

Since there's no concept of a session bean in a console app, dropping

@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) from getSession() should do it. Then you don't even need to override getSession().

Luanne
  • 19,145
  • 1
  • 39
  • 51