Skip to content

Instantly share code, notes, and snippets.

@dalexandrov
Created February 23, 2021 14:12
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 dalexandrov/e5a4743d72eef0184b24ad3ffb3ca121 to your computer and use it in GitHub Desktop.
Save dalexandrov/e5a4743d72eef0184b24ad3ffb3ca121 to your computer and use it in GitHub Desktop.
public class Neo4jCdiExtension implements Extension {
private static final String NEO4J_METRIC_NAME_PREFIX = "neo4j";
void afterBeanDiscovery(@Observes AfterBeanDiscovery addEvent) {
addEvent.addBean()
.types(Driver.class)
.qualifiers(Default.Literal.INSTANCE, Any.Literal.INSTANCE)
.scope(ApplicationScoped.class)
.name(Driver.class.getName())
.beanClass(Driver.class)
.createWith(creationContext -> {
org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
Config helidonConfig = MpConfig.toHelidonConfig(config).get(NEO4J_METRIC_NAME_PREFIX);
ConfigValue<Neo4j> configValue = helidonConfig.as(Neo4j::create);
if (configValue.isPresent()) {
return configValue.get().driver();
}
throw new Neo4jException("There is no Neo4j driver configured in configuration under key 'neo4j");
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment