What changed in Jersey 2.26+ ?
If you look at the release notes for Jersey 2.26 there is a brief note about changing the dependency injection mechanism. There is not much detail on how this is going to impact a user of some of Jersey's features - specifically injecting method parameters. Quoting from the release notes:attempt to make Jersey core independent of any specific injection framework. As you might now, Jersey 2.x is (was!) pretty tightly dependent on HK2, which sometimes causes issues (esp. when running on other injection containers. Jersey now defines it's own injection facade, which, when implemented properly, replaces all internal Jersey injection.
Jersey source commits of interest
For the adventurous souls, the following is a list of commits that changed the classes, interfaces and mechanisms around field and method parameters injection.- commit 854d7bdbb35b15881ae02f8884d51dd9d6ebf3cc
Author: Marek Potociar
Date: Mon Feb 20 14:53:18 2017 +0100 - commit 682a61257bd463fc1204efe447c6684b595a6d54
Author: Marek Potociar
Date: Mon Feb 20 18:45:45 2017 +0100 - commit 1f4614787c4cfddb5d9177c6c2a663b96ab673cc
Author: Petr Bouda
Date: Thu Apr 27 15:53:45 2017 +0200
The core changes are around AbstractValueFactoryProvider, ValueFactoryProvider and the mechanism for actually getting to the value to be injected.
So what should I do?
- Replace usage of org.glassfish.jersey.server.spi.internal.ValueFactoryProvider with org.glassfish.jersey.server.spi.internal.ValueParamProvider.
- Replace usage of org.glassfish.jersey.server.internal.inject.AbstractValueFactoryProvider with org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider.
- If your implementation of AbstractValueFactoryProvider had a super call, note that the constructor signature has changed. The constructor parameters are now Provider
mpep, Parameter.Source... compatibleSources .
.
The return type of AbstractValueParamProvider.createValueProvider() is now
java.util.function.Function
So you need to create a FunctionalInterface that returns the object that you need.
Once these changes are made your parameter injection will work just as before. To make things more future-proof it will be best to use the new AbstractBinder and Binder that Jersey 2.26 has introduced. This will decouple your code very firmly from HK2.
It is still a matter of concern that these classes are 'internal' Jersey classes. Thus there is lack of documentation and no clear warning on changes.
No comments:
Post a Comment