Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTEasy Singleton resource with constructor injection failing with RESTEASY003190 #16475

Closed
chris-asl opened this issue Apr 13, 2021 · 5 comments · Fixed by #16494
Closed

RESTEasy Singleton resource with constructor injection failing with RESTEASY003190 #16475

chris-asl opened this issue Apr 13, 2021 · 5 comments · Fixed by #16494
Labels
area/resteasy-classic kind/bug Something isn't working
Milestone

Comments

@chris-asl
Copy link
Contributor

chris-asl commented Apr 13, 2021

Describe the bug

When using constructor injection in a non annotated resource (reproducer link), e.g.

@Path("/hello")
public class GreetingResource {

    GreetingService greetingService;

    @Inject
    public GreetingResource(GreetingService greetingService) {
        this.greetingService = greetingService;
    }

the program spins up successfully.

Given the default resource scope, as defined by quarkus.resteasy.singleton-resources is Singleton, why do I get an error if I annotate the class with @Singleton, as I did here?

The program fails upon startup with:

...
Caused by: java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: org.acme.getting.started.GreetingResource
	at org.jboss.resteasy.spi.metadata.ResourceBuilder.getConstructor(ResourceBuilder.java:852)
...

It seems there's a difference with explicitly setting the scope to Singleton with it being set-up "automatically".
If I am missing something, a pointer towards the docs would be more than welcome.

I don't know if this is related to #6722 or #7495.

Expected behavior

As in both cases the scope effectively is Singleton, shouldn't the behaviour be the same?

Actual behavior

Annotating a RESTEasy Resource with @Singleton, I get the aforementioned error.

To Reproduce

Link to a small reproducer (preferably a Maven project if the issue is not Gradle-specific).

Or attach an archive containing the reproducer to the issue.

Steps to reproduce the behavior:

  1. git clone [email protected]:chris-asl/quarkus-mcve.git
  2. ./mvnw quarkus:dev

Configuration

Defaults

Environment:

Output of uname -a or ver

Linux homer 5.8.0-48-generic #54~20.04.1-Ubuntu SMP Sat Mar 20 13:40:25 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

Quarkus version or git rev

1.13.1.Final (also tested with 1.12.2.Final)

Build tool

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/chris/.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3
Java version: 11.0.10, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.8.0-48-generic", arch: "amd64", family: "unix"

FYI @el10686

@chris-asl chris-asl added the kind/bug Something isn't working label Apr 13, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 13, 2021

/cc @manovotn, @mkouba

@quarkus-bot quarkus-bot bot added the area/arc Issue related to ARC (dependency injection) label Apr 13, 2021
@mkouba
Copy link
Contributor

mkouba commented Apr 13, 2021

I can confirm that the behavior varies. If there is no scope annotation present then the no-args constructor is generated automatically. However, if the javax.inject.Singleton is added you need to add the no-args constructor manually. It's interesting that if you add @RequestScoped the no-args constructor is also generated although I don't see the javax.enterprise.context package in the list of compatible annotations here: https://github.com/quarkusio/quarkus/blob/main/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java#L452-L463

CC @geoand

@mkouba
Copy link
Contributor

mkouba commented Apr 13, 2021

It's interesting that if you add @RequestScoped the no-args constructor is also generated although I don't see the javax.enterprise.context package in the list of compatible annotations here...

In this case, the no-args constructor is generated by ArC because @RequestScoped is a normal scope.

@mkouba
Copy link
Contributor

mkouba commented Apr 13, 2021

@geoand I think that we could just add the javax.inject to the list of compatible packages. I can send a PR tomorrow.

@geoand
Copy link
Contributor

geoand commented Apr 13, 2021

@mkouba yeah, that makes perfect sense!

mkouba added a commit to mkouba/quarkus that referenced this issue Apr 14, 2021
@mkouba mkouba added area/resteasy-classic and removed area/arc Issue related to ARC (dependency injection) labels Apr 14, 2021
@quarkus-bot quarkus-bot bot added this to the 2.0 - main milestone Apr 14, 2021
@gsmet gsmet modified the milestones: 2.0.0.Alpha1, 1.13.3.Final Apr 26, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/resteasy-classic kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants