question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@Path annotation not used if inherited from an interface

See original GitHub issue

The @Path annotation is not used if it is inherited from an interface.

Example for a base interface:

@Path("/persons")
public interface PersonResource {
}

The client interface now inherits from the above one:

@RegisterRestClient(configKey = "person-service")
public interface PersonService extends PersonResource {
}

This will lead to the following (wrong) call:

http://localhost:8080/whatever

Adding a superfluous @Path on the rest client interface makes it work correctly:

@Path("/persons")
@RegisterRestClient(configKey = "person-service")
public interface PersonService extends PersonResource {
}

This will lead to the following (correct) call:

http://localhost:8080/persons/whatever

The expected behaviour would be, that the @Path annotation is correctly used from the parent interface and there is no need to duplicate it.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
andymc12commented, Mar 28, 2020

Hi @michael-schnell , thanks for opening this issue. We try to follow JAX-RS’s lead where possible, and in section 3.6 of the JAX-RS Spec, it talks about annotation inheritance - specifically:

JAX-RS annotations may be used on the methods and method parameters of a super-class or an implemented interface. Such annotations are inherited by a corresponding sub-class or implementation class method provided that the method and its parameters do not have any JAX-RS annotations of their own. Annotations on a super-class take precedence over those on an implemented interface. The precedence over conflicting annotations defined in multiple implemented interfaces is implementation specific. Note that inheritance of class or interface annotations is not supported.

So for MP Rest Client, implementations should support annotation inheritance on methods, but not on interfaces.

That said, I don’t see that this is documented in the MP Rest Client specification - and I don’t think there are any TCK tests for this. So, if you don’t mind, I’d like to keep this issue open to clarify this behavior in the spec/TCK.

Thanks again!

0reactions
CENGOiSMcommented, Jan 29, 2021

I am facing the same issues right now. Searching for a solution I found that annotating @Provider on the implemented class is solving the mentioned problems. What do you think about this approach, am I missing something?

@Path("/persons")
public interface PersonResource {
}

@Provider
public class PersonResource implements PersonResource {
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Annotation is not inherited from interface method
Inherited : Note that this meta-annotation type has no effect if the annotated type is used to annotate anything other than a class....
Read more >
JAX-RS - Annotation Inheritance - LogicBig
Inheritance of class or interface annotations is not supported. That means only method level JAX-RS are inherited to the sub-classes.
Read more >
JAX-RS: Path annotations from inherited interface shouldn't be ...
JAX-RS: Path annotations from inherited interface shouldn't be suggested in completion in case Path overrided in class which implement interface.
Read more >
Chapter 51. Annotation Inheritance Red Hat JBoss Fuse 6.2
JAX-RS's annotation inheritance also extends to support for interfaces. Implementation classes inherit the JAX-RS annotations used in the interface they ...
Read more >
Inherited (Java SE 18 & JDK 18) - Oracle Help Center
Note that this meta-annotation interface has no effect if the annotated interface is used to annotate anything other than a class.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found