Field injection does not work for all classes
See original GitHub issueI steped into a limitation with field injection during the introduction of the new elasticsearch client for version 7.X. The class RestHighLevelClient is not injectable because it contains final fields:
WELD-001480: Bean type class org.elasticsearch.client.RestHighLevelClient is not proxyable because it contains a final method public final org.elasticsearch.action.index.IndexResponse org.elasticsearch.client.RestHighLevelClient.index(org.elasticsearch.action.index.IndexRequest,org.elasticsearch.client.RequestOptions) throws java.io.IOException - Producer Method [RestHighLevelClient] with qualifiers [@Default @Named @Any] declared as [[BackedAnnotatedMethod] @Produces @ApplicationScoped @Named public static io.apiman.manager.test.server.TestCdiFactory.provideStorageJestClient()]
Using a wrapper for the class works:
But I personally not like this approach that much, because we have an unnecessary getter call to get the client from the wrapper. I would prefer to avoid injections by passing the client via parameter of the EsStorage initilize method or constructor e.g. here: https://github.com/apiman/apiman/blob/8e8fc6d8a64b270ed536b1df0ffd43137b89f854/manager/test/api/src/main/java/io/apiman/manager/test/server/TestCdiFactory.java#L123
@EricWittmann @msavy What you are thinking about this?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
I don’t have a strong preference here. Injection is great when it works well but it doesn’t always. In this case feel free to update the
initialize
method to accept the client as a parameter. Or, if it makes sense, just have theEsStorage
class instantiate the client directly.Ah yes good point - there may be a test vs. production difference that I’m not thinking about. Either way, as long as you consider that option (even if you choose the alternative) I’m happy. 😃