整合CXF和Spring

以REST服务为例。

导入cxf和spring的支持库,载入spring配置文件和cxf的bean文件,cxf的bean文件可以命名为cxf-servlet.xml,以备生产环境使用,以下所列方式为测试使用,服务运行在开发环境中。

import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;

ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{“applicationContext.xml”,”cxf-servlet.xml”});
在cxf-servlet.xml配置文件中设置资源类和Server。
<jaxrs:server id=”test” address=”http://localhost:8080/test”>
        <jaxrs:serviceBeans>
             <ref bean=”testResource” />
        </jaxrs:serviceBeans>
</jaxrs:server>
<bean id=”testtResource” class=”testResource”> </bean>
从ApplicationContext中得到Server,然后创建,sleep这个线程。
JAXRSServerFactoryBean sfb = (JAXRSServerFactoryBean)ctx.getBean(“test”);
sfb.create();
VN:F [1.9.7_1111]
留下你的评价吧
Rating: 3.7/10 (3 votes cast)
整合CXF和Spring, 3.7 out of 10 based on 3 ratings

相关文章

Tags: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*