Build fails for @Provider exception mapper
See original GitHub issuestarting with 0.23.2 I get [ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:0.25.0:build (default) on project demo: Failed to build a runnable JAR: Failed to build a runner jar: Failed to augment application classes: Build failure: Build failed due to errors [ERROR] [error]: Build step io.quarkus.arc.deployment.ArcProcessor#registerBeans threw an exception: javax.enterprise.inject.spi.DefinitionException: Bean class com.demo.excmapper.IllegalArgumentExceptionMapper declares multiple scope type annotations: javax.enterprise.context.Dependent, javax.inject.Singleton
Steps to reproduce the behavior:
- Create sample hello project
- Add the class
import org.eclipse.microprofile.metrics.Counter;
import org.eclipse.microprofile.metrics.annotation.Metric;
import javax.inject.Inject;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
@Provider
public class IllegalArgumentExceptionMapper implements ExceptionMapper<IllegalArgumentException> {
@Inject
@Metric(absolute = true, name = "error_count", description = "count", displayName = "error_count")
private Counter counter;
@Override
public Response toResponse(IllegalArgumentException exception) {
counter.inc();
return Response.status(500).entity("illegal").build();
}
}
- run mvn package getting-started.zip
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Defining exception mappers for resource exceptions and errors
Create a class that implements the javax.ws.rs.ext.ExceptionMapper class and annotate the class with the javax.ws.rs.ext.Provider annotation.
Read more >ExceptionMapper provider not working with jersey
I read the documentation of Jersey and i undestand that i can register the exception mappers using @provider in the class. But the...
Read more >Exception Handling | RESTful Java with JAX-RS 2 ... - dennis-xlc
The JAX-RS runtime throws this exception if a MessageBodyWriter fails or if there is an exception thrown from an ExceptionMapper. ServiceUnavailableException ...
Read more >Chapter 27. Exception Handling - JBoss.org
ExceptionMappers are custom, application provided, components that can catch thrown application exceptions and write specific HTTP responses.
Read more >Chapter 50. Handling Exceptions Red Hat Fuse 7.2
If an exception occurs while the exception mapper is building the Response object, the runtime will send a response with a status of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh, now I get it, so we’ll make the Metrics
AnnotationsTransformer
run after the one for Resteasy, and also when checking whether there is a scope present already, instead of doingBuiltinScope.isDeclaredOn(ctx.getTarget().asClass())
, we will doBuiltinScope.isIn(ctx.getAnnotations())
(so it will see scopes added by other transformers), does that sound good?I guess we could then discard the checks (in the Metrics transformer) whether the bean is a JAX-RS endpoint/provider, but for being extra safe I would maybe keep them… (?)
Fixed by https://github.com/quarkusio/quarkus/pull/4688 .