tomcat - Apache CXF + Spring Java config + replace beans.xml -
i try replace beans.xml javaconfig (spring). in beans.xml have following configuration:
<bean id="testwebservice" class="at.test.testwebservice" /> <jaxws:endpoint id="test" address="/testwebservice_v100" implementor="#testwebservice" /> <jaxrs:server id="testrestservice" address="/rest/test" name="testrestservice"> <jaxrs:servicebeans> <ref bean="testwebservice" /> </jaxrs:servicebeans> <jaxrs:providers> <ref bean="jsonprovider" /> <ref bean="datehandler" /> </jaxrs:providers> </jaxrs:server>
at moment have config.java class contains beans beans.xml.
config.java:
@configuration public class config { @bean public testwebservice testwebservice() { return new testwebservice(); }
all beans configured @controller , resources marked @autowired.
@webservice(endpointinterface = "at.test.interfaces.itestwebservice") @transactional @controller public class testwebservice extends abstractsessionwebservice implements itestwebservice {
it works fine, no errors , tomcat starts fine. how configure jaxws:endpoint , jaxrs:server? have more 1 entries in beans file. how configure multiple jaxws:endpoint , jaxrs:server entries?
please try this
@autowired applicationcontext ctx; @bean public servletregistrationbean dispatcherservlet() { cxfservlet cxfservlet = new cxfservlet(); return new servletregistrationbean(cxfservlet, "/rest/*"); } @bean(name="cxf") public springbus springbus() { return new springbus(); } @bean public server jaxrsserver() { list providers = new linkedlist(); providers.add(new jsonprovider()); providers.add(new datehandler()); linkedlist<resourceprovider> resourceproviders = new linkedlist<>(); (string beanname : ctx.getbeandefinitionnames()) { if (ctx.findannotationonbean(beanname, path.class) != null) { springresourcefactory factory = new springresourcefactory(beanname); factory.setapplicationcontext(ctx); resourceproviders.add(factory); } } jaxrsserverfactorybean factory = new jaxrsserverfactorybean(); factory.setbus(springbus()); factory.setproviders(providers); factory.setresourceproviders(resourceproviders); return factory.create(); } }
and in testrestservice endpoint,
@endpoint public class testrestserviceendpoint implements testrestservice { @payloadroot(localpart=testwebservice_v100, namespace=namespace) public <returntype> <methodname>(<requesttype> request) { // ws bl return; } }
Comments
Post a Comment