Java config + neo4j

364 views
Skip to first unread message

Stacy Tyler Young

unread,
Aug 2, 2012, 1:33:31 AM8/2/12
to Neo4j
I've been experimenting with using java config for neo4j setup.

@Configuration
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
public class DatabaseConfiguration extends Neo4jConfiguration
{
    @Override
    @Autowired
    public void setGraphDatabaseService( GraphDatabaseService service ) {
        super.setGraphDatabaseService( service );
    }

    @Bean(destroyMethod = "shutdown")
    public GraphDatabaseService graphDatabaseService() {
        final Map<String,String> options = new HashMap<String, String>();
        options.put( "enable_remote_shell", "true" );
        return new EmbeddedGraphDatabase( "/usr/share/actual/db", options );
    }
}

Is this valid? It appears to work but I'm wondering if I need to do anything with Neo4jConfiguration? Lastly, any insight on how I can replicate <neo4j:repositories base-package="com.foo" />?

Thanks!
Stace

Lasse Westh-Nielsen

unread,
Aug 2, 2012, 5:02:17 AM8/2/12
to ne...@googlegroups.com

Stacy Tyler Young

unread,
Aug 2, 2012, 7:43:34 AM8/2/12
to ne...@googlegroups.com

Ah, thanks so much!

Stacy Tyler Young

unread,
Aug 2, 2012, 11:40:26 AM8/2/12
to ne...@googlegroups.com
Has this only been used in the context of test case? I'm attempting to use as config from web.xml but not much luck. I may have to pass on this for now anyway as I cannot move to snapshot build. :(

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            com.actual.configuration.DatabaseConfiguration.Config
        </param-value>
    </context-param>

public class DatabaseConfiguration extends Neo4jConfiguration
{
    @Configuration
    @EnableNeo4jRepositories(basePackages = "com.acme.repository")
    static class Config extends Neo4jConfiguration
    {
        @Bean
        public GraphDatabaseService graphDatabaseService() {
            final Map<String,String> options = new HashMap<String, String>();
            options.put( "enable_remote_shell", "true" );
            return new EmbeddedGraphDatabase( "/foo", options );
        }
    }
}

I've tried a number of permutations but all end in exceptions at startup.

Stace

Lasse Westh-Nielsen

unread,
Aug 3, 2012, 6:23:04 AM8/3/12
to ne...@googlegroups.com
Stacy,

What concrete errors are you getting?

Would it be possible to recreate the problem in a small test project and share that?

Lasse

Stacy Tyler Young

unread,
Aug 3, 2012, 3:55:41 PM8/3/12
to ne...@googlegroups.com
A very non-descriptive exception relating to annotations. My apologies, I meant to include the exception information in that original email. I've since had to revert to xml config due to not being able to use a snapshot build at this point in the project.

I will revisit later this month and report back.

Stace
Reply all
Reply to author
Forward
0 new messages