My Jersey Application container is shutdown with below exception message.
java.lang.IllegalStateException: ServiceLocatorImpl(__HK2_Generated_0,0,1879131528) has been shut down
at org.jvnet.hk2.internal.ServiceLocatorImpl.checkState(ServiceLocatorImpl.java:2288)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getServiceHandleImpl(ServiceLocatorImpl.java:629)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getServiceHandle(ServiceLocatorImpl.java:622)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getServiceHandle(ServiceLocatorImpl.java:640)
at org.jvnet.hk2.internal.FactoryCreator.getFactoryHandle(FactoryCreator.java:103)
... 59 common frames omitted
Wrapped by: org.glassfish.hk2.api.MultiException: A MultiException has 1 exceptions. They are:
1. java.lang.IllegalStateException: ServiceLocatorImpl(__HK2_Generated_0,0,1879131528) has been shut down
Whenever the above error is coming the application is not able to process the request. It repeatedly showing the same message and also my spring application container also down.Below is the error message i am getting repatedly.
org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'daoQuery': Singleton bean creation not allowed while the singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
My Glassfish Jersey Version is 2.22.2.
The above thing happens only in heavy load.
We analyzed the issue and found that this issue happen in multiple scenarios.
We corrected those two points, but still we are getting the same error in heavy load.
Is there any way to prevent or fix issue?
You should upgrade to latest 2.28 latest version, or at least 2.26 version which fixes HK2 issues
Another bigger change in Jersey code is 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.
Don't be mistaken - Jersey still runs on hk2. But it should be possible to get rid off that dependency when other container provides same functionality. As already mentioned, the motivation is to be able to integrate seamlessly with other frameworks, like cdi, guice, etc. This is still work in progress and there is one consequence: user has to provide Jersey injection implementation. The only one which is 100% ready right now is based on hk2:
<groupId>org.glassfish.jersey.inject</groupId> <artifactId>jersey-hk2</artifactId> <version>2.26</version>