-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Closed
Copy link
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancementA general enhancement
Milestone
Description
Andy Wilkinson opened SPR-16001 and commented
In a similar vein to #19474, I just wrote the following:
@Bean
public HttpHandler httpHandler(
ObjectProvider<WebSessionManager> webSessionManagerProvider) {
WebHttpHandlerBuilder builder = WebHttpHandlerBuilder
.applicationContext(this.applicationContext);
WebSessionManager webSessionManager = webSessionManagerProvider
.getIfAvailable();
if (webSessionManager != null) {
builder.sessionManager(webSessionManager);
}
return builder.build();
}
I'd prefer to avoid the local variable and null check. Something like this:
@Bean
public HttpHandler httpHandler(
ObjectProvider<WebSessionManager> webSessionManagerProvider) {
WebHttpHandlerBuilder builder = WebHttpHandlerBuilder
.applicationContext(this.applicationContext);
webSessionManagerProvider.consumeIfAvailable(
(webSessionManager) -> builder.sessionManager(webSessionManager));
return builder.build();
}
Affects: 5.0 RC4
Issue Links:
- Provide computeIfAbsent-like method on ObjectProvider [SPR-14980] #19546 Provide computeIfAbsent-like method on ObjectProvider
Referenced from: commits e927cae
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancementA general enhancement