Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jersey-dev] Cannot @Inject into ExceptionMapper

Hi,

I'm attempting to inject some RequestScoped objects into an ExceptionMapper:

    public class NotFoundExceptionMapper extends ExceptionMapperBase
implements ExceptionMapper<NotFoundException>
    {

        @Inject TemplateCall templateCall;
    ...

In my ResourceConfig I have

    register(new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            bindFactory(TemplateCallProvider.class).to(TemplateCall.class).
            proxy(true).proxyForSameScope(false).in(RequestScoped.class);
        }
    });
    ...
    register(new NotFoundExceptionMapper());
    // register(NotFoundExceptionMapper.class); // also tried this, same effect

However I get an error when NotFoundException should be mapped:

04-Apr-2020 10:57:22.213 SEVERE [main]
org.apache.catalina.core.ApplicationContext.log Servlet.init() for
servlet [com.atomgraph.server.Application] threw exception
MultiException stack 1 of 2
        java.lang.RuntimeException: java.lang.InstantiationException:
com.atomgraph.processor.util.TemplateCall_$$_jvstb48_0
                at
org.jvnet.hk2.internal.ProxyUtilities$4.run(ProxyUtilities.java:157)
                at java.security.AccessController.doPrivileged(Native Method)
                at
org.jvnet.hk2.internal.ProxyUtilities.secureCreate(ProxyUtilities.java:128)
                at
org.jvnet.hk2.internal.ProxyUtilities.generateProxy(ProxyUtilities.java:194)
                at
org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2074)
                at
org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:666)
                at
org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:54)
                at
org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:988)
                at
org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:998)
                at
org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:976)
                at
org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.inject(AbstractHk2InjectionManager.java:202)
                at
org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.inject(ImmediateHk2InjectionManager.java:30)
    ...
MultiException stack 2 of 2
        java.lang.IllegalArgumentException: While attempting to create
a Proxy for com.atomgraph.processor.util.TemplateCall in scope
org.glassfish.jersey.process.internal.RequestScoped an error occured
while creating the proxy
                at
org.jvnet.hk2.internal.ProxyUtilities.generateProxy(ProxyUtilities.java:201)
                at
org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2074)
                at
org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:666)
                at
org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:54)
                at
org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:988)
                at
org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:998)
                at
org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:976)
                at
org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.inject(AbstractHk2InjectionManager.java:202)
                at
org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.inject(ImmediateHk2InjectionManager.java:30)
    ...

Looking at similar problems online, my guess is that it has to do with
a RequestScoped object being injected into Singleton. However I
haven't been able to find a solution yet.

Thanks.


Martynas


Back to the top