-
Notifications
You must be signed in to change notification settings - Fork 41.2k
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
Add auto-configuration for Neo4j driver #22301
Conversation
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.
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
...figure/src/main/java/org/springframework/boot/autoconfigure/neo4j/Neo4jSpringJclLogging.java
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
@Nested |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
(Again) thanks for the valuable feedback. ❤️ |
Yes! Thank you again. |
I hope that I fixed or clarified the problems you have found. |
Is there anything left to do for me or do you need any additional information? |
I am good for this one, thanks @meistermeier! |
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
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 |
Thanks a lot @snicoll . Rebasing and ensuring everything still works as expect is on my list next. |
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