Skip to content

Add auto-configuration for Neo4j driver #22301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

meistermeier
Copy link
Contributor

@meistermeier meistermeier commented Jul 10, 2020

This commit adds the support for creating a managed instance of the Neo4j Java driver.
The low-level support for Neo4j is helpful in situations where the high-level abstraction of Spring Data Neo4j is not needed.

The PR is the foundation for the Spring Data Neo4j Starter update PR #22299 because it provides classes needed in the updated SDN starter.

Also there is the suggested related change for the initializer that enables the Neo4j driver dependency and allows the autoconfiguration to kick in: spring-io/start.spring.io#483

This commit adds the support for creating a managed instance of the
Neo4j Java driver.
The low-level support for Neo4j is helpful in situations where the
high-level abstraction of Spring Data Neo4j is not needed.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 10, 2020
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 14, 2020
@wilkinsona wilkinsona added this to the 2.4.x milestone Jul 14, 2020
@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Jul 14, 2020
@snicoll snicoll changed the title Add autoconfiguration for Neo4j driver. Add auto-configuration for Neo4j driver Jul 17, 2020
Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the PR. Getting auto-configuration for the driver that Spring Data bits then reuse is exactly the kind of arrangement we're aiming at so that's great to see it happening for Neo4j too.

I've made a few comments. There are similar formatting and code style as in the other PR.

@ConditionalOnMissingBean(Driver.class)
Driver neo4jDriver(final Neo4jDriverProperties driverProperties) {

final AuthToken authToken = driverProperties.getAuthentication().asAuthToken();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style, our codebase doesn't use final (neither in attribute, nor in constructor argument).

* @since 2.4.0
*/
@ConfigurationProperties(prefix = "spring.neo4j")
public class Neo4jDriverProperties {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the spring.neo4j namespace, this should be named Neo4jProperties. Usage of this class should also be named consistently. If you think the driver part is important, then it should be reflected in the namespace.

this.kerberosTicket = kerberosTicket;
}

AuthToken asAuthToken() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although a number of other properties have the same structure, we are trying to make sure @ConfigurationProperties-annotated type are as simple as possible and do not contain any logic. Please move this to the configuration if possible.

return this.authentication.asAuthToken();
}

public Config asDriverConfig() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark than asAuthToken

@ConditionalOnClass(Driver.class)
@EnableConfigurationProperties(Neo4jDriverProperties.class)
@Import(DriverConfiguration.class)
public class Neo4jDriverAutoConfiguration {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other driver auto-config, this should be Neo4jAutoConfiguration.


AuthToken asAuthToken() {

boolean hasUsername = StringUtils.hasText(this.username);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code might a bit messy here but I had hoped if that makes sense to provide a fallback for spring.data.neo4j.usename and spring.data.neo4j.password. Same, a metadata with warning deprecation should indicate the replacement.

}
}

@Nested
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I've indicated on the other PR we don't use @Nested anywhere so I'd prefer to leave it out of this PR if possible.


private Neo4jDriverProperties load(String... properties) {

AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even such tests use the application context runner. It is a superior option compared to a simple handling of the context as you still need to handle the context otherwise.

Given that the logic for the properties object would be moved elsewhere, this might not be necessary after all.

@@ -1432,6 +1439,7 @@ bom {
"spring-boot-starter-logging",
"spring-boot-starter-mail",
"spring-boot-starter-mustache",
"spring-boot-starter-neo4j",
Copy link
Member

@snicoll snicoll Jul 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be removed as there is no starter for the driver (and there shouldn't be any if all that's needed is the driver.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Jul 17, 2020
@meistermeier
Copy link
Contributor Author

(Again) thanks for the valuable feedback. ❤️
I would now focus on this PR to get the foundation for the SDN 6 changes (and compilable code). At least I see a benefit of having these independent changes merged first and base the other PR(s) on this.

@snicoll
Copy link
Member

snicoll commented Jul 17, 2020

Yes! Thank you again.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 17, 2020
@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jul 17, 2020
@meistermeier
Copy link
Contributor Author

I hope that I fixed or clarified the problems you have found.
Unfortunately I have overseen the formatting issues in the first run(s). There was also one in the Neo4jProperties but a gradle format did not touch it and in the next run it wasn't there anymore 🤷‍♀️

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 17, 2020
@snicoll snicoll removed the for: team-attention An issue we'd like other members of the team to review label Jul 18, 2020
@meistermeier
Copy link
Contributor Author

Is there anything left to do for me or do you need any additional information?

@snicoll
Copy link
Member

snicoll commented Jul 20, 2020

I am good for this one, thanks @meistermeier!

@snicoll snicoll self-assigned this Jul 20, 2020
@snicoll snicoll modified the milestones: 2.4.x, 2.4.0-M2 Jul 27, 2020
snicoll pushed a commit that referenced this pull request Jul 27, 2020
This commit adds the support for creating a managed instance of the
Neo4j Java driver. The low-level support for Neo4j is helpful in
situations where the high-level abstraction of Spring Data Neo4j is not
needed.

See gh-22301
snicoll added a commit that referenced this pull request Jul 27, 2020
@snicoll snicoll closed this in e6f1819 Jul 27, 2020
@snicoll snicoll removed the status: feedback-provided Feedback has been provided label Jul 27, 2020
@snicoll
Copy link
Member

snicoll commented Jul 27, 2020

Thanks a lot @meistermeier (and @michael-simons). I've polished things quite a bit in 8c418ad and we have enough runway to adapt things if necessary.

I am going to review the actuator stuff that are relevant to the driver next. And finally move to Spring Data 2020.0.0-SNAPSHOT to upgrade to SDN 6.x. If you have time to rebase #22299, that would be much appreciated.

@meistermeier meistermeier deleted the feature/neo4j-driver-autoconfiguration branch July 27, 2020 15:55
@meistermeier
Copy link
Contributor Author

Thanks a lot @snicoll . Rebasing and ensuring everything still works as expect is on my list next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants