MyNeo4jConfiguration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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