Inject Spring Bean as Endpoint with Jersey SpringServlet -


migrating jax-rs service cxf on jersey because of issues wls 12.

i have interface has jax-rs annotations , 2 classes implement (one being class fulfills default functionality , 1 stubbed implementation).

in cxf, can use property drive implementation class fulfills rest request through spring injection:

   <alias name="restproxyapi${restproxyapi.sib:impl}" alias="restproxyapiendpoint" />     <jaxrs:server id="jaxrs.restproxyapi" address="/">     <jaxrs:servicebeans>         <ref bean="restproxyapiendpoint" />     </jaxrs:servicebeans>    </jaxrs:server> 

i don't see way jersey. jersey seems want me use spring's component scanning , declare package api endpoint existw in. not want do. there way in jersey can utilize bean id resource jersey uses fulfill request coming springservlet?

i've been looking solution of issue while well. however, think there's no such mechanism interface,abstract class/implement used spring ioc.

there's 1 way can come don't bother worrying declaration , implementation on configuration of xmls. directly set implementation class bean in spring's beans.xml. example:

there're 2 different implementations same restful api, let's resta , restb, , code may like...

@path("/restapi") public class resta {     @post     @path("post/")     public string print(@context httpservletrequest req, inputstream is) {        // resta:      } }  @path("/restapi") public class restb {     @post     @path("post/")     public string print(@context httpservletrequest req, inputstream is) {        // restb:      } } 

then, in beans setting xml, declare both of class beans restful request, , mark 1 of them ... (here, resta handle request http://x.x.x.x/restapi/post )

<beans>     <bean id="resta" class="a.b.x.resta" />     <!-- <bean id="restb" class="a.b.y.restb" /> --> </beans> 

and when want switch restful api implementation, mark or remove other beans.

although approach doesn't count real solution, works managing multiple implementations same restful api.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -