payara / Payara

Payara Server is an open source middleware platform that supports reliable and secure deployments of Java EE (Jakarta EE) and MicroProfile applications in any environment: on premise, in the cloud or hybrid.
http://www.payara.fish
Other
886 stars 307 forks source link

Unsatisfied dependencies for type [...] with qualifiers @RestClient at injection point [UnbackedAnnotatedField] @Inject @RestClient / FISH-764 #4704

Open Lars5678 opened 4 years ago

Lars5678 commented 4 years ago

Description


As described under https://docs.payara.fish/docs/5.201/documentation/microprofile/rest-client.html I registered an MP Rest Client as an interface. This is injected into a CDI bean.

If I start the application in a Payara Micro, the application starts up and works perfectly. However, I get a warning:

Component of class interface de.xx.prototype.jsf.clients.ConfigResourceService cannot be instantiated and will be ignored.

Is the message correct?

However, this is just a warning but everything works.

But....

When I start the application in Payara Full I get a deployment exception and the application will not be deployed.

Expected Outcome

Same behavior like in Payara Micro. Just a warning but application will be deployed. Optimally, no misleading warning either.

Current Outcome

Payara Micro - Warning:

Component of class interface de.xx.prototype.jsf.clients.ConfigResourceService cannot be instantiated and will be ignored.

Payara Full - Exception:

` [#|2020-06-08T14:35:23.712+0200|SCHWERWIEGEND|Payara 5.201|javax.enterprise.system.core|_ThreadID=1;_ThreadName=main;_TimeMillis=1591619723712;_LevelValue=1000;_MessageID=NCLS-CORE-00026;| Exception during lifecycle processing org.glassfish.deployment.common.DeploymentException: CDI deployment failure:WELD-001408: Unsatisfied dependencies for type ConfigResourceService with qualifiers @RestClient at injection point [UnbackedAnnotatedField] @Inject @RestClient private de.xx.prototype.jsf.admin.AdminController.configResourceService at de.xx.prototype.jsf.admin.AdminController.configResourceService(AdminController.java:0) -- WELD-001408: Unsatisfied dependencies for type ConfigResourceService with qualifiers @RestClient at injection point [UnbackedAnnotatedField] @Inject @RestClient private de.xx.prototype.jsf.admin.AdminController.configResourceService at de.xx.prototype.jsf.admin.AdminController.configResourceService(AdminController.java:0)

at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:378)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:290)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:143)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:164)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:526)
at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:512)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:487)
at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:496)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:93)
at org.glassfish.weld.WeldDeployer.processApplicationLoaded(WeldDeployer.java:513)
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:424)
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:344)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepare(ApplicationLifecycle.java:568)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:561)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:558)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:554)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/javax.security.auth.Subject.doAs(Subject.java:361)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:553)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:584)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:576)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/javax.security.auth.Subject.doAs(Subject.java:361)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:575)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1496)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:120)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1878)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1754)
at com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.executeCommand(CommandExecutorImpl.java:183)
at com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.run(CommandExecutorImpl.java:96)
at fish.payara.boot.runtime.BootCommand.execute(BootCommand.java:69)
at fish.payara.boot.runtime.BootCommands.executeCommands(BootCommands.java:136)
at fish.payara.boot.runtime.BootCommands.executeCommands(BootCommands.java:130)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain$Launcher.doBootCommands(GlassFishMain.java:294)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain$Launcher.launch(GlassFishMain.java:133)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain.main(GlassFishMain.java:109)
at com.sun.enterprise.glassfish.bootstrap.ASMain.main(ASMain.java:54)

`

Steps to reproduce (Only for bug reports)

1 -** Create an Interface as MP Rest Client

2 -** Inject in CDI Bean

3 -** Start runtime

4 -** See server logs

Samples

Environment

rdebusscher commented 4 years ago

Hi Lars,

This fell through the cracks for a reply.

Can you try on the latest version. I tried the following and I don't have any problem.

@Path("/api/hello")
@Produces(MediaType.TEXT_PLAIN) 
@Consumes(MediaType.TEXT_PLAIN)
@RegisterRestClient  // Required to enable injection of this interface
@RequestScoped 
public interface HelloService {
    @Path("{name}")
    @GET
    String hello(@PathParam("name") String name);
}

And using it

@RequestScoped
public class ClientResource {
    @Inject
    @RestClient
    private HelloService helloService;

Thanks Regards Rudy

Lars5678 commented 4 years ago

I'm sorry about it. Unfortunately, I can not longer reproduce the problem. I have tested it with the 5.2020.3 as well as with the 5.201 each FULL and have no more exception. Maybe I've changed something in the meantime.

Only the messages mentioned above continue to appear. I think this issue can be closed as not reproduceable.

rdebusscher commented 4 years ago

Yes the message appears because of conflicting rules around JAX-RS and MicroProfile Rest.

Closing it as functionality is ok.

Lars5678 commented 4 years ago

@rdebusscher I was able to recreate the problem. The problem always occurs if no scope is specified. If I give RequestScoped or Dependent it works.

As I said, in Payara Micro it works without specifying a scope. In Payara Full, unfortunately, only with the specification of a scope.

Why it works in the micro but not in the full I don't know. But my understanding was that @RegisterRestClient automatically sets the service Dependent.

This works both in Payara Micro and Full

@RegisterRestClient
@Path("/v1/maintenance")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
@ClientHeaderParam(name = "Authorization", value = "{generateAuthHeader}")
@Dependent
public interface ConfigResourceService

This works only in Payara Micro but not in Full

@RegisterRestClient
@Path("/v1/maintenance")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
@ClientHeaderParam(name = "Authorization", value = "{generateAuthHeader}")
public interface ConfigResourceService
Lars5678 commented 4 years ago

So try to remove the Scope from HelloService and try with Micro and then with Full

rdebusscher commented 4 years ago

Hi Lars,

Removing the scope still results in a deployment without exceptions. I tried with a few variations around the scope of the JAX-RS resource where the 'interface' is injected and beans.xml. But no luck.

Can you upload a small, simple reproducer that shows the problem?

Thanks Rudy

Lars5678 commented 4 years ago

Strange. I'm trying to provide a small reproducer.

Lars5678 commented 4 years ago

https://github.com/LarsBrenker/pay4704

Enclosed the reproducer. Just check out and build the image (with the Payara Full). Then it should come to the error. If the annotation @Dependent is commented in the class de.larsbrenker.reproducer.ConfigResourceService, the error is gone. In Payara Micro you can also do without the annotation.

I hope it works. It is my first public GitHub Project

rdebusscher commented 4 years ago

Hi Lars,

Thank you for the reproducer and yes, the Github repo is fine.

I see that you want to inject in a Faces defined CDI bean. We have to investigate this more in-depth as this is an unforeseen factor for the MP RestClient spec. I also see no beans.xml defined which also can have an influence.

I'll keep you updated on my research results later on.

Best Regards Rudy

Lars5678 commented 4 years ago

Hi Rudy,

I adjusted the reproducer.

Maybe it's related to the beans.xml. But as I said: There has to be a difference between Payara Micro and Payara Server.

rdebusscher commented 4 years ago

Hi Lars,

When I add a beans.xml with bean-discovery-mode="annotated" (or all) there is no longer a difference between Payara Server and Payara Micro.

I'll investigate this further, also in the light of a possible Jakarta Web Profile certification of Payara Micro.

Regards Rudy

AlanRoth commented 4 years ago

Hi @LarsBrenker, I was able to reproduce the issue in the latest release, so I made an internal ticket FISH-764.

Lars5678 commented 3 years ago

Hi @rdebusscher ,

I lost sight of this ticket a bit.

I added the beans.xml. For me it only works with the Bean Discovery Mode "all". With "annotated" I also get the error.

The CDI Spec says "It is strongly recommended you use" annotated "." it would be nice if we can find a solution for this.

I adjusted the reproducer. Beans.xml added and the Payara Image 5.2021.4 used

Lars5678 commented 2 years ago

Unfortunately, the error still exists in the current version 5.2022.2