Saturday 15 May 2010

java - JAX-RS: How to extend Application class to scan packages? -



java - JAX-RS: How to extend Application class to scan packages? -

currently, similar

import javax.annotation.nonnull; import javax.ws.rs.applicationpath; import javax.ws.rs.core.application; import java.util.collections; import java.util.hashset; import java.util.set; @applicationpath("oauth") public class oauthapplication extends application { final set<class<?>> classes = new hashset<>(); @nonnull @override public set<class<?>> getclasses() { classes.add(registerresource.class); homecoming collections.unmodifiableset(classes); } }

no if add together 10 new resources on applicationpath, need

classes.add(<classname>.class);

ten times, tedious , forgetful well.

does jax-rs or resteasy provide way can mention bundle name , classes scanned under it?

i know jersey has

public class myapplication extends resourceconfig { public myapplication() { packages("org.foo.rest;org.bar.rest"); } }

reference

any thoughts/ideas?

update

seems can next in web.xml

<context-param> <param-name>resteasy.scan</param-name> <param-value>true</param-value> </context-param>

is there specific java equivalent?

"is there specific java equivalent?"

simply leave class empty, meaning not override getclasses() or getsingletons(). per spec - 2.3.2:

[...]

in either of latter 2 cases, if both application.getclasses , application.getsingletons homecoming empty list root resource classes , providers packaged in web application must included in published jax-rs application. if either getclasses or getsingletons homecoming non-empty list classes or singletons returned must included in published jax-rs application.

so can do

@applicationpath("oauth") public class oauthapplication extends application {}

and classpath scanned @path , @provider classes. override either method (returning non-empty set), , classes added.

it should noted public map<string, object> getproperties() can safely overridden. can utilize add together arbitrary properties (even register classes/features), seen here, or if need configure provider, can in feature or dynamicfeature seen here

java rest jersey jax-rs resteasy

No comments:

Post a Comment