Skip to content

Automate JAX-RS root resource registration #12075

Closed
@flangknecht

Description

@flangknecht

Currently JAX-RS resources have to be manually enumerated in a ResourceConfig bean when using Jersey like in the following sample from Spring Boot Jersey Samples.

@Component
public class JerseyConfig extends ResourceConfig {

	public JerseyConfig() {
		register(Endpoint.class);
		register(ReverseEndpoint.class);
	}
}

I've found this to almost always be the only kind of setup done in those beans and therefore think that this is something that can be automated using Spring Boot's autoconfiguration approach.

The JAX-RS 2.1 spec, section 2.3.2 mentions that, when running in a Servlet environment, and

  • "no Application subclass is present, JAX-RS implementations are REQUIRED to dynamically
    add a servlet [...] and to automatically discover all root resource classes and providers"
  • "an Application subclass is present" and "both Application.getClasses and Application.getSingletons return an empty collection" then "all root resource classes and
    providers packaged in the web application MUST be included and the JAX-RS implementation REQUIRED to discover them automatically by scanning a .war file as described above"

Since (the last time I checked) Jersey's JAR - scanning doesn't seem to bode well with Spring Boot - repackaged JARs I think this behavior should be upheld by Spring means.

This would help deliver more of the "it just works" - feeling one has come used to associate with Spring Boot.

I propose to automatically provide a ResourceConfig similar to what's proposed in #11948.
Additionally any JAX-RS root resource classes and providers that are managed by Spring should automatically be registered in the absence of another ResourceConfig bean.

Did I miss anything and this sort of behavior is already possible using the tools we have today?

If not: Is this something you'd be interested in including in Spring Boot?
If anyone's interested I'd be willing to draw something up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions