Skip to content

Incorrect work of @Named annotation - #66

Open
Ivan-nikitko wants to merge 5 commits into
bootique:masterfrom
Ivan-nikitko:named_injected_class_notFound
Open

Incorrect work of @Named annotation #66
Ivan-nikitko wants to merge 5 commits into
bootique:masterfrom
Ivan-nikitko:named_injected_class_notFound

Conversation

@Ivan-nikitko

@Ivan-nikitko Ivan-nikitko commented Jan 9, 2023

Copy link
Copy Markdown

Solution for work of @Named annotation in bootique-jersey module.
Partialy solution for work of @Named annotation in bootique-jersey-jakarta module. Tests for unsolved issues added.

See #82

That combinations works well in jersey-jakarta;

@jakarta.inject.Inject
@jakarta.inject.Named("")

and

@jakarta.inject.Inject
@jakarta.inject.Qualifier

There's a problem with. Added tests for this cases:

 @javax.inject.Inject
 @javax.injectNamed("")
 
 @BQInject
 @javax.injectNamed("")
 
 @lavax.inject.Inject
 @javax.inject.Qualifier

@Ivan-nikitko
Ivan-nikitko force-pushed the named_injected_class_notFound branch from bcfdebe to a265a58 Compare January 9, 2023 13:46
@Ivan-nikitko
Ivan-nikitko force-pushed the named_injected_class_notFound branch from a265a58 to 3319b0c Compare January 9, 2023 13:49
@andrus

andrus commented Sep 28, 2023

Copy link
Copy Markdown
Contributor

Two notes:

  • I tried this PR with the latest code, and the test fails (see below). Did it work before, or is the PR itself is to demonstrate a bug?
  • Whatever we do in bootique-jersey , needs to be duplicated to bootique-jersey-jakarta
org.opentest4j.AssertionFailedError: Runtime 'app failed to start: [1: jersey==org.glassfish.jersey.servlet.ServletContainer@baa68670{jsp=null,order=-1,inst=true,async=true,src=EMBEDDED:null,STARTED}]

at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:42)
at org.junit.jupiter.api.Assertions.fail(Assertions.java:147)
at io.bootique.junit5.handler.app.ManagedTestRuntime.run(ManagedTestRuntime.java:73)
at io.bootique.junit5.handler.app.ManagedTestRuntime.startIfNeeded(ManagedTestRuntime.java:57)
at io.bootique.junit5.handler.app.BQAppRegistry.lambda$onAppFieldFound$2(BQAppRegistry.java:57)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134)
at io.bootique.junit5.handler.app.BQAppRegistry.onAppFieldFound(BQAppRegistry.java:57)
at io.bootique.junit5.handler.app.ClassAppRegistry.lambda$beforeContext$0(ClassAppRegistry.java:39)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1085)
at io.bootique.junit5.handler.app.ClassAppRegistry.beforeContext(ClassAppRegistry.java:39)
at io.bootique.junit5.handler.app.BQAppHandler.beforeAll(BQAppHandler.java:40)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$12(ClassBasedTestDescriptor.java:395)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllCallbacks(ClassBasedTestDescriptor.java:395)

Caused by: javax.servlet.ServletException: jersey==org.glassfish.jersey.servlet.ServletContainer@baa68670{jsp=null,order=-1,inst=true,async=true,src=EMBEDDED:null,STARTED}
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:651)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:415)
at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize$2(ServletHandler.java:725)
at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
...
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:89)
at org.eclipse.jetty.server.Server.doStart(Server.java:415)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)
at io.bootique.jetty.command.ServerCommand.run(ServerCommand.java:52)
at io.bootique.command.MultiCommand.run(MultiCommand.java:83)
at io.bootique.run.DefaultRunner.run(DefaultRunner.java:43)
at io.bootique.BQRuntime.run(BQRuntime.java:76)
at io.bootique.junit5.handler.app.ManagedTestRuntime.run(ManagedTestRuntime.java:70)
... 51 more
Caused by: A MultiException has 1 exceptions.  They are:
1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=ResourceInjectionIT$InjectedServiceInterface,parent=ResourceInjectionIT$NamedFieldInjectedResource,qualifiers={@javax.inject.Named(value="A")},position=-1,optional=false,self=false,unqualified=null,1163189762)

at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:51)
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:214)
at org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.inject(ImmediateHk2InjectionManager.java:30)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:427)
...
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:339)
at javax.servlet.GenericServlet.init(GenericServlet.java:180)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:633)
... 75 more
Caused by: org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=ResourceInjectionIT$InjectedServiceInterface,parent=ResourceInjectionIT$NamedFieldInjectedResource,qualifiers={@javax.inject.Named(value="A")},position=-1,optional=false,self=false,unqualified=null,1163189762)
... 93 more


@Ivan-nikitko

Ivan-nikitko commented Sep 29, 2023

Copy link
Copy Markdown
Author

It just a bug demonstrating. @Inject annotation dosen't work in this case (@BQInject work well).
Second note - I will take it into account

@andrus

andrus commented Sep 29, 2023

Copy link
Copy Markdown
Contributor

Ah, cool. Can we open a ticket under "Issues", describing the bug and linking to this PR?

@Ivan-nikitko

Copy link
Copy Markdown
Author

Sure! I'll do it.

@Ivan-nikitko Ivan-nikitko changed the title added test for injection with annotation "@Named" Incorrect work of "@Named" annotation Oct 6, 2023
@stariy95 stariy95 changed the title Incorrect work of "@Named" annotation Incorrect work of @Named annotation Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants