Skip to content

Instantly share code, notes, and snippets.

@netrebel
Created August 11, 2017 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netrebel/87b6cdb302c324b71080dda5bfa4aeb1 to your computer and use it in GitHub Desktop.
Save netrebel/87b6cdb302c324b71080dda5bfa4aeb1 to your computer and use it in GitHub Desktop.
MyNeo4jConfiguration
@EnableAutoConfiguration
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = {"com.enernoc.yggi.neo4j.service"})
@EnableNeo4jRepositories(basePackages = "com.enernoc.yggi.neo4j.repository")
@EnableConfigurationProperties(ConfigProperties.class)
public class MyNeo4jConfiguration extends WebMvcConfigurerAdapter {
private static final Logger LOG = LoggerFactory.getLogger(MyNeo4jConfiguration.class);
private final ConfigProperties configProperties;
@Autowired
public MyNeo4jConfiguration(ConfigProperties configProperties) {
this.configProperties = configProperties;
}
private org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
LOG.info("Connecting to Neo4j with uri: {}", configProperties.getNeo4jUri());
config.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.bolt.driver.BoltDriver")
.setURI("bolt://" + configProperties.getNeo4jUri())
.setEncryptionLevel("NONE")
.setTrustStrategy("TRUST_ON_FIRST_USE")
.setTrustCertFile("file:///tmp/cert");
return config;
}
@Bean
public SessionFactory getSessionFactory() {
return new SessionFactory(getConfiguration(), "com.enernoc.yggi.neo4j.domain", "com.enernoc.yggi.neo4j.results");
}
@Bean
public OpenSessionInViewInterceptor openSessionInViewInterceptor() {
OpenSessionInViewInterceptor openSessionInViewInterceptor =
new OpenSessionInViewInterceptor();
openSessionInViewInterceptor.setSessionFactory(getSessionFactory());
return openSessionInViewInterceptor;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addWebRequestInterceptor(openSessionInViewInterceptor());
}
@Bean
public Neo4jTransactionManager transactionManager() throws Exception {
return new Neo4jTransactionManager(getSessionFactory());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment