Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quarkus does not use JaxRs @Path when declared in interface in an external jar

I have a Java interface which declares all things related to JaxRs like this:

@Path("/notes-service")
public interface NotesApi {

  @POST
  @Path("/notes")
  @Consumes({ "application/json" })
  @Produces({ "application/json" })
  Response createNote(
    @HeaderParam("Accept-Language") @DefaultValue("en") String acceptLanguage,
    @Valid CreateNoteDTO createNoteDTO);

}

The interface is shipped as an external dependency as a jar.

And an implementation in my service:

@ApplicationScoped
@Transactional
public class NotesService implements NotesApi {

  @Override
  public Response createNote(String range, CreateNoteDTO createNoteDTO) {
    // ...
  }
}

Such a setup like above doesn't work. It returnes 404 for an endpoint /notes-service/notes

However when I copy the @Path part into the implenentation, everything works just fine:

@ApplicationScoped
@Transactional
@Path("/notes-service")
public class NotesService implements NotesApi {

  @Override
  public Response createNote(String range, CreateNoteDTO createNoteDTO) {
    // ...
  }
}

Also another workaaround: When I copy-paste the interface into my service then it also works without @Path declaration in an implementation.

This means that @Path annotation on interface level works just fine (I have checked it with a minimal service). But it doesn't work when the interface comes as a dependency.

Is it a bug in Quarkus or an expected behavior?

like image 683
zolv Avatar asked Oct 27 '25 03:10

zolv


1 Answers

You need to add an empty beans.xml in your external project in src/main/resources/META-INF, so that Quarkus scans your external jar file.

Quarkus documentation also lists other ways to make beans discoverable:

  • dependencies that contain a beans.xml descriptor (content is ignored)
  • dependencies that contain a Jandex index - META-INF/jandex.idx
  • dependencies referenced by quarkus.index-dependency in application.properties
  • Quarkus integration code.

https://quarkus.io/guides/cdi-reference#bean_discovery

like image 164
Serkan Avatar answered Oct 29 '25 19:10

Serkan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!