praspa
praspa

Reputation: 634

JAX-RS: Is it possible to have an externally configurable @PATH?

Is it possible to load the value for the @PATH annotation from configuration (web.xml, etc) for a given class?

@Path(<value loaded from config>)
public class myRestService {
...

Upvotes: 2

Views: 342

Answers (3)

R...
R...

Reputation: 2620

You can add path programmatically, as shown in JAX-RS Jersey, how to dynamic adding resources or providers to Application

which means you can then wire it your configuration .

Upvotes: 0

lefloh
lefloh

Reputation: 10971

Independent of JAX-RS: Annotations in Java are compile time constants so they can't be changed at runtime.

I don't know your use case but possible ways to change the values of the annotations are:

  • Replacing variables before compilation, e.g. through a maven plugin.
  • Adding the @Path annotations dynamically like described here.
  • Using one generic ResourceClass mapped to /* which decides which subresource should be returned.

No comment if one of these approaches makes sense as I don't know why you want to change them. As the URI names a resource I don't see any reason to change it. See also: Cool URIs don't change

Update: JAX_RS_SPEC-60 requests "A Dynamic way to register JAX-RS resources (not based on annotations)".

Upvotes: 2

traianus
traianus

Reputation: 111

According to JAX-RS specification (here), there is no standard way to do this, I think.

Upvotes: 0

Related Questions