diff --git a/core-server/src/main/java/org/glassfish/jersey/server/ApplicationHandler.java b/core-server/src/main/java/org/glassfish/jersey/server/ApplicationHandler.java index 315cb181d9..5191ee0e78 100644 --- a/core-server/src/main/java/org/glassfish/jersey/server/ApplicationHandler.java +++ b/core-server/src/main/java/org/glassfish/jersey/server/ApplicationHandler.java @@ -134,6 +134,8 @@ import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.hk2.utilities.binding.ScopedBindingBuilder; +import org.jvnet.hk2.external.runtime.ServiceLocatorRuntimeBean; + import jersey.repackaged.com.google.common.base.Function; import jersey.repackaged.com.google.common.base.Predicate; import jersey.repackaged.com.google.common.collect.Collections2; @@ -594,9 +596,22 @@ private ServerRuntime initialize(Iterable componentProviders) .to(routingStage) .to(resourceFilteringStage) .build(Routing.matchedEndpointExtractor()); + final ServerRuntime serverRuntime = locator.createAndInitialize(ServerRuntime.Builder.class) .build(rootStage, compositeListener, processingProviders); + // clear HK2 caches + final ServiceLocatorRuntimeBean serviceLocatorRuntimeBean = locator.getService(ServiceLocatorRuntimeBean.class); + if (serviceLocatorRuntimeBean != null) { + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.fine(LocalizationMessages.CLEARING_HK_2_CACHE( + serviceLocatorRuntimeBean.getServiceCacheSize(), + serviceLocatorRuntimeBean.getReflectionCacheSize())); + } + serviceLocatorRuntimeBean.clearReflectionCache(); + serviceLocatorRuntimeBean.clearServiceCache(); + } + // Inject instances. for (final Object instance : componentBag.getInstances(ComponentBag.EXCLUDE_META_PROVIDERS)) { locator.inject(instance); diff --git a/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties b/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties index 3a5ab34501..a4676a7114 100644 --- a/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties +++ b/core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties @@ -130,6 +130,7 @@ form.param.method.error=The "@FormParam" is utilized when the request method is get.consumes.entity=A HTTP GET method, {0}, should not consume any entity. get.consumes.form.param=A HTTP GET method, {0}, should not consume any form parameter. get.returns.void=A HTTP GET method, {0}, returns a void type. It can be intentional and perfectly fine, but it is a little uncommon that GET method returns always "204 No Content". +clearing.hk2.cache=Clearing Jersey HK2 caches. Service cache size: {0}, reflection cache size: {1}. chunked.output.closed=This chunked output has been closed. illegal.client.config.class.property.value="{0}" property value ({1}) does not represent a valid client configuration class. Falling back to "{2}". init.msg=Initiating Jersey application, version {0}...