How are SessionScoped beans supposed to work with java.lang.Optional?
See original GitHub issueCurrently it does not seem possible to have optional values for session scopes CDI beans?!
According to: https://github.com/eclipse/microprofile-config/blob/master/spec/src/main/asciidoc/configexamples.asciidoc
someone always have to provide a default value.
==> Optional
is not Serializable
Also this usage of Optional
is questionable:
void method(@ConfigProperty(name = "a.config.key") final Optional<String> value)){...}
Optional should be used for return types only!
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Working with scoped beans when the scope is optional?
If I have a session, I look into the cache in the session. If the bean doesn't exist, yet, I use the objectFactory...
Read more >Introduction to Contexts and Dependency Injection - Quarkus
The type is used to build the set of bean types. In this case, it will be double and java.lang.Object . No scope...
Read more >Overview of Bean Scopes in Quarkus | Marcel Kliemannel
An in-depth description of all built-in bean scopes provided by Quarkus, the creation of custom scopes, and how to force the initialization ...
Read more >Configuring Managed Beans - The Java EE 6 Tutorial
When a page references a managed bean for the first time, the JavaServer Faces implementation initializes it based on a @ManagedBean annotation in...
Read more >Beans
Suppose that we have two existing Java classes that we've been using for ... For example, any web application may have session scoped...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for your reply. I think this should be mentioned in the documentation. E.g. in the mentioned example: https://github.com/eclipse/microprofile-config/blob/master/spec/src/main/asciidoc/configexamples.asciidoc
Cheers
@svenhaag The optionality is for some properties that might have not got value assigned. The best practices is that you should provide default value. If you do need to have optional value, you can use programmatic lookup e.g.
ConfigProvider.getConfig.getOptionalValue()
instead of injection on yourSessionScoped
orConversationScoped
or any other passivation scoped beans.The injection for the type
Optional
is fine for non passivation scoped beans though.