From 9d4364be0d4dbc1dfdb77eae5a5f4a234759542a Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Wed, 14 Apr 2021 08:43:22 +0200 Subject: [PATCH] Fix JAX-RS @Singleton resource with constructor injection - resolves #16475 --- .../ResteasyServerCommonProcessor.java | 1 + .../ConstructorInjectionResourceTestCase.java | 8 ++++++- ...SingletonConstructorInjectionResource.java | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 extensions/resteasy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/SingletonConstructorInjectionResource.java diff --git a/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java b/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java index 965d7218bd412..cf5e28f75f0c9 100755 --- a/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java +++ b/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java @@ -459,6 +459,7 @@ List registerCompatibleAnnotationPrefixes prefixes.add(new AllowedJaxRsAnnotationPrefixBuildItem("javax.annotation.security")); prefixes.add(new AllowedJaxRsAnnotationPrefixBuildItem("jakarta.annotation.security")); prefixes.add(new AllowedJaxRsAnnotationPrefixBuildItem("java.lang")); + prefixes.add(new AllowedJaxRsAnnotationPrefixBuildItem("javax.inject")); return prefixes; } diff --git a/extensions/resteasy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/ConstructorInjectionResourceTestCase.java b/extensions/resteasy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/ConstructorInjectionResourceTestCase.java index 65e2a713584ad..6d5686fa59108 100644 --- a/extensions/resteasy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/ConstructorInjectionResourceTestCase.java +++ b/extensions/resteasy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/ConstructorInjectionResourceTestCase.java @@ -14,10 +14,16 @@ public class ConstructorInjectionResourceTestCase { @RegisterExtension static QuarkusUnitTest runner = new QuarkusUnitTest() .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) - .addClasses(ConstructorInjectionResource.class, Service.class)); + .addClasses(ConstructorInjectionResource.class, SingletonConstructorInjectionResource.class, + Service.class)); @Test public void testConstructorInjectionResource() { RestAssured.when().get("/ctor").then().body(Matchers.is("service")); } + + @Test + public void testSingletonConstructorInjectionResource() { + RestAssured.when().get("/ctor-single").then().body(Matchers.is("service")); + } } diff --git a/extensions/resteasy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/SingletonConstructorInjectionResource.java b/extensions/resteasy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/SingletonConstructorInjectionResource.java new file mode 100644 index 0000000000000..2bf60255953dc --- /dev/null +++ b/extensions/resteasy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/SingletonConstructorInjectionResource.java @@ -0,0 +1,21 @@ +package io.quarkus.resteasy.test; + +import javax.inject.Singleton; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Singleton +@Path("/ctor-single") +public class SingletonConstructorInjectionResource { + + final Service service; + + public SingletonConstructorInjectionResource(Service service) { + this.service = service; + } + + @GET + public String val() { + return service.execute(); + } +}